pytest automatically skips test cases that you don't want to execute

foreword

When executing the use case framework in batches, we do not want to execute some use cases or use case files in a certain directory. What should we do?

The pytest automation framework provides methods to skip test cases that you don't want to execute.

Let's get started! ! ! (Remember to like and collect not to miss it)

1. Unconditional skip, can be used for use case methods and classes

@pytest.mark.skip(reason="No reason not to execute")

 

2. Conditional skipping, different skipping conditions can be superimposed on a use case, but as long as the use case meets one of the skipping conditions, the use case can be skipped (can be used for use case methods and classes)

@pytest.mark.skipif(num<=6, reason="num is less than or equal to 6 does not execute")

 

3. Module skipping

① The module is skipped unconditionally: pytestmark = pytest.mark.skip()

 

③ Skip the remaining module method: pytest.skip(reason='', allow_module_level=True), used for skipping on use cases 

 

4. Use the conftest.py file to set the use case skip in the file directory

Add the following parameter fields under the conftest.py file to specify skipped file directories and files

collect_ignore_glob = ['test_case/test_*.py','test_assert*.py']

Finally, look at the execution results 

 

 Finally:  In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free 【保证100%免费】

                                 How to obtain the full set of materials: Click the small card below to get it yourself

                                                     

Guess you like

Origin blog.csdn.net/2301_76643199/article/details/132024603