Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

1 pytest designated test case for a series of learning initiated by exercises (2)

Shulou Source: shulou.com Published: 2022-06-03 06:52:40 09月23日 Update

I. Background

There are 4 test classes and 15 test cases under test module. Practice to become familiar with the specified set of test cases provided by pytest.

Pytest provides a variety of ways to specify test case sets:

Specify module Specify keyword Specify file Specify expression of tag

II. PRACTICE

The following practices are performed in pycharm.

Designated module

[Run/Debug Configuration]-[Additional Arguments] parameter is empty, run directly.

As you can see from the results, all 15 test cases were executed. specified keyword

At runtime, you can specify some test cases by specifying the-k parameter. Here is help for the-k parameter.

Example 1:

[Run/Debug Configuration]-[Additional Arguments]-[-k "test_20"]. By specifying keywords, 5 test cases matching keywords were executed.

Example 2:

[Run/Debug Configuration]-[Additional Arguments]-[-k "not test_20"], ignoring test_20* test cases by specifying keywords

specified file

[Run/Debug Configuration]-[Working directory], which is set to pytest file, which is equivalent to executing test_xx.py file in dayByDay directory.

Specify the expression of the tag. Add the tag to the class or method, such as @pytest.marker.webtestbr/> Add the tag to the class or method, such as @ pytest.marker.webtest.

III. SUMMARY

Pytest provides a way to sort test cases and select them flexibly. At the same time, when constructing the name of the test case, it is necessary to define keywords that are easy to identify.

IV. References

https://docs.pytest.org/en/latest/example/markers.html#using-k-expr-to-select-tests-based-on-their-name

Tags: Test key keyword file tag parameter method run example way expression practice under information reference can be passed at the same time multiple identification directory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Shulou Tech Info Apple MariaDB