Skip to content

Commit

Permalink
Fix sys.path.insert for project path: insert absolute path (#638)
Browse files Browse the repository at this point in the history
Fixes #637
  • Loading branch information
blueyed authored Aug 20, 2018
1 parent 43ff7bb commit 2bd442f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def find_django_path(args):

project_dir = find_django_path(args)
if project_dir:
sys.path.insert(0, str(project_dir))
sys.path.insert(0, str(project_dir.absolute()))
return PROJECT_FOUND % project_dir
return PROJECT_NOT_FOUND

Expand Down
18 changes: 18 additions & 0 deletions tests/test_manage_py_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ def test_foobar():
assert outcomes['passed'] == 1


@pytest.mark.django_project(project_root='django_project_root',
create_manage_py=True)
def test_django_project_found_absolute(django_testdir, monkeypatch):
"""This only tests that "." is added as an absolute path (#637)."""
django_testdir.create_test_module("""
def test_dot_not_in_syspath():
import sys
assert '.' not in sys.path[:5]
""")
monkeypatch.chdir('django_project_root')
# NOTE: the "." here is important to test for an absolute path being used.
result = django_testdir.runpytest_subprocess('-s', '.')
assert result.ret == 0

outcomes = result.parseoutcomes()
assert outcomes['passed'] == 1


@pytest.mark.django_project(project_root='django_project_root',
create_manage_py=True)
def test_django_project_found_invalid_settings(django_testdir, monkeypatch):
Expand Down

0 comments on commit 2bd442f

Please sign in to comment.