Install Pytest for multiple modules

Let's say I have the following test structure:

  test /
   module1 /   
     test1.py
   module2 /
     test2.py
   module3 /
     test3.py

How to configure any method to call only once before all these tests?

+8
source share
2 answers

You can use stand-alone lights:

# content of test/conftest.py import pytest @pytest.fixture(scope="session", autouse=True) def execute_before_any_test(): # your setup code goes here, executed ahead of first test 

See pytest dxt for more details.

+13
source

If you mean only once in each test case run, then tuning and disassembling is what you are looking for

 def setup_module(module): print ("This will at start of module") def teardown_module(module): print ("This will run at end of module") 

Similarly, you can have setup_function and teardown_function that will run at the beginning and at the end of each test function in turn. You can also add a tuning and breaking member function to the test classes to run at the beginning and end of the test class.

0
source

Source: https://habr.com/ru/post/955404/


All Articles