diff --git a/tests/conftest.py b/tests/conftest.py index 25685914..bc53b9c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,21 @@ +import sys from pathlib import Path import pytest +# each test runs on cwd to its temp dir +@pytest.fixture(autouse=True) +def go_to_tmpdir(request): + # Get the fixture dynamically by its name. + tmpdir = request.getfixturevalue("tmpdir") + # ensure local test created packages can be imported + sys.path.insert(0, str(tmpdir)) + # Chdir only for the duration of the test. + with tmpdir.as_cwd(): + yield + + @pytest.fixture def temp_dir(tmp_path: Path): """Create a temporary directory with some files inside it.