Skip to content

Fix sys.path.insert for project path: insert absolute path #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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