Skip to content

Commit 109c2e2

Browse files
committed
Workaround for cwd bug
Based on pytest-dev/pytest#1235 (comment)
1 parent e06e083 commit 109c2e2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
import pytest
3+
4+
15
def pytest_configure(config):
26
import sys
37

@@ -22,3 +26,14 @@ def move_to_front(items, test_name):
2226
test = [fn for fn in items if fn.name == test_name]
2327
if test:
2428
items.insert(0, items.pop(items.index(test[0])))
29+
30+
31+
@pytest.fixture
32+
def restore_working_directory(tmpdir, request):
33+
previous_cwd = os.getcwd()
34+
tmpdir.chdir()
35+
36+
def return_to_previous():
37+
os.chdir(previous_cwd)
38+
39+
request.addfinalizer(return_to_previous)

tests/test_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_plugins_asgi_wrapper(app_client):
191191
assert "fixtures" == response.headers["x-databases"]
192192

193193

194-
def test_plugins_extra_template_vars():
194+
def test_plugins_extra_template_vars(restore_working_directory):
195195
for client in make_app_client(
196196
template_dir=str(pathlib.Path(__file__).parent / "test_templates")
197197
):

0 commit comments

Comments
 (0)