Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-03 07:33:48 09月29日 Update

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.

Tags: Tests plug-ins methods tags valid successful usage scenarios examples that is meaning results conclusions questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Shulou Tech Info Microsoft Shulou Technology