Debian Codegraph @

conftest.py

raw
1 import pytest
2
3 # https://stackoverflow.com/questions/46962007/how-to-automatically-change-to-pytest-temporary-directory-for-all-doctests
4
5
6 @pytest.fixture(autouse=True)
7 def _docdir(request):
8 # Trigger ONLY for the doctests.
9 doctest_plugin = request.config.pluginmanager.getplugin("doctest")
10 if isinstance(request.node, doctest_plugin.DoctestItem):
11 # Get the fixture dynamically by its name.
12 tmpdir = request.getfixturevalue("tmpdir")
13
14 # Chdir only for the duration of the test.
15 with tmpdir.as_cwd():
16 yield
17
18 else:
19 # For normal tests, we have to yield, since this is a yield-fixture.
20 yield