August 2018
Beginner
160 pages
4h 8m
English
The @pytest.mark.usefixtures mark can be used to apply one or more fixtures to tests, as if they have the fixture name declared in their parameter list. This can be an alternative in situations where you want all tests in a group to always use a fixture that is not autouse.
For example, the code below will ensure all tests methods in the TestVirtualEnv class execute in a brand new virtual environment:
@pytest.fixturedef venv_dir(): import venv with tempfile.TemporaryDirectory() as d: venv.create(d) pwd = os.getcwd() os.chdir(d) yield d os.chdir(pwd)@pytest.mark.usefixtures('venv_dir')class TestVirtualEnv: ...
As the name indicates, you can pass multiple fixtures names to the decorator:
@pytest.mark.usefixtures("venv_dir", ...Read now
Unlock full access