Initial and final check when starting the pytest test suite

I have productive code that creates configuration files in my $HOME folder and runs my tests in an isolated environment. I am fixing $HOME in conftest.py . However, Iโ€™m not sure if this works at all, and there may be broken written test functions.

To guarantee the validity of my test suite, I would like to pre-test the corresponding files in $HOME , and I want to perform a final check after running the test suite.

How can I achieve this using the "official" pytest tools? I have a dirty hack that works, but confuses reporting.

My test suite is now correct, and this question is not out of curiosity because I would like to know more about pytest .


Addition: The same question, but a different use case: I would like to check if a third-party plugin really populates the version. If not, I would like to show the message and stop py.test.

+8
python
source share
1 answer

Do you think you are writing fittings for pytest with session coverage? Something like:

 @pytest.fixture(scope="session") def global_check(request): assert initial_condition def final_check(request): assert final_condition request.addfinalizer(final_check) return request 

If all your other devices inherit from global_check , then initial_condition will be confirmed at the beginning of all your test runs, and final_condition will be confirmed at the end of your test runs.

+1
source share

All Articles