August 2018
Beginner
160 pages
4h 8m
English
It is possible to apply a fixture to all of the tests in a hierarchy, even if the tests don't explicitly request a fixture, by passing autouse=True to the @pytest.fixture decorator. This is useful when we need to apply a side-effect before and/or after each test unconditionally.
@pytest.fixture(autouse=True)def setup_dev_environment(): previous = os.environ.get('APP_ENV', '') os.environ['APP_ENV'] = 'TESTING' yield os.environ['APP_ENV'] = previous
An autouse fixture is applied to all tests which the fixture is available for use with:
In other words, ...
Read now
Unlock full access