Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report