Pytest: how to execute some code once at the start of when each test_file.py is called?

159 views Asked by At

My test repository is like so:

-Test:
    - common_library.py
    - conftest.py
    - Feature_folder_01:
        - test_file_01.py
        - test_file_02.py
    - Feature_folder_02:
        - test_file_01.py
        - test_file_02.py
        - test_file_02.py

I want to execute some code at the beginning of each test_file_.py. I cannot have the code in conftest.py because the code for some basic calls (serial_ command class) e.g. serial read-write is in common_library.py and conftest is compiled first. So it does not have access to the calls in common-library. If a fixture is used the fixture will have to be copied at that start of each test_file_.py (there are several) and it will be executed for every parameterization of the tests.

Is there a possible solution to this?

0

There are 0 answers