Skip to content

Commit 2bd442f

Browse files
authored
Fix sys.path.insert for project path: insert absolute path (#638)
Fixes #637
1 parent 43ff7bb commit 2bd442f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pytest_django/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def find_django_path(args):
139139

140140
project_dir = find_django_path(args)
141141
if project_dir:
142-
sys.path.insert(0, str(project_dir))
142+
sys.path.insert(0, str(project_dir.absolute()))
143143
return PROJECT_FOUND % project_dir
144144
return PROJECT_NOT_FOUND
145145

tests/test_manage_py_scan.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ def test_foobar():
2323
assert outcomes['passed'] == 1
2424

2525

26+
@pytest.mark.django_project(project_root='django_project_root',
27+
create_manage_py=True)
28+
def test_django_project_found_absolute(django_testdir, monkeypatch):
29+
"""This only tests that "." is added as an absolute path (#637)."""
30+
django_testdir.create_test_module("""
31+
def test_dot_not_in_syspath():
32+
import sys
33+
assert '.' not in sys.path[:5]
34+
""")
35+
monkeypatch.chdir('django_project_root')
36+
# NOTE: the "." here is important to test for an absolute path being used.
37+
result = django_testdir.runpytest_subprocess('-s', '.')
38+
assert result.ret == 0
39+
40+
outcomes = result.parseoutcomes()
41+
assert outcomes['passed'] == 1
42+
43+
2644
@pytest.mark.django_project(project_root='django_project_root',
2745
create_manage_py=True)
2846
def test_django_project_found_invalid_settings(django_testdir, monkeypatch):

0 commit comments

Comments
 (0)