[TIP] py.test: Best way of having a fixture autoused "almost all of the time"

Paul Moore p.f.moore at gmail.com
Fri Aug 8 05:41:06 PDT 2014

I've got a situation where I want to use a py.test autouse fixture to
make sure my tests run in a clean environment. The idea is that I have
a fixture marked as autouse which uses application features to isolate
the test environment from the user's config files. But obviously I
don't want that fixture to activate when actually testing the
functionality it uses!

The simple approach would be to have a structure

            def isolate_env():
        ... all the rest of the application tests

but I'm not a huge fan of the extra directory level, for a single
file. Is it possible to say that I *don't* want isolate_env activated
in the test_isolation.py file?


More information about the testing-in-python mailing list