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

Using pytest-dependency to solve the problem of dependency between use cases

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

Share

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

Usage scenario: test B can be effectively carried out only after Test A has passed successfully.

Use this plug-in to mark a test as a dependency on other test, and those test that depend on it will be skipped when the execution of the dependency fails.

-example above:

Installation: pytest-dependency

Pip install pytest-dependency

Use:

Import pytest@pytest.mark.dependency () def test_01 (test): assert False@pytest.mark.dependency (depends= ["test_01"]) def test_02 (test): print ("execute Test 2")

Take a look at the results:

Test_01 is a dependency of test_02, so after test_01 fails, test_02 is skipped

Conclusion:

1. Install the plug-in first

2. The way to use it is to mark the dependent method with @ pytest.mark.dependency () and use @ pytest.mark.dependency (depends= ["test_name"]) to refer to the dependency.

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