Skip to content

Avoid crash after OSError during django path detection #664

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 1 commit into from
Oct 16, 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
6 changes: 4 additions & 2 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def _handle_import_error(extra_message):

def _add_django_project_to_path(args):
def is_django_project(path):
return path.is_dir() and (path / 'manage.py').exists()
try:
return path.is_dir() and (path / 'manage.py').exists()
except OSError:
return False

def arg_to_path(arg):
# Test classes or functions can be appended to paths separated by ::
Expand All @@ -130,7 +133,6 @@ def arg_to_path(arg):
def find_django_path(args):
args = map(str, args)
args = [arg_to_path(x) for x in args if not x.startswith("-")]
args = [p for p in args if p.is_dir()]

if not args:
args = [pathlib.Path.cwd()]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_manage_py_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,15 @@ def test_django_project_found_invalid_settings_version(django_testdir, monkeypat
result = django_testdir.runpytest_subprocess('django_project_root', '--help')
assert result.ret == 0
result.stdout.fnmatch_lines(['*usage:*'])


@pytest.mark.django_project(project_root='django_project_root',
create_manage_py=True)
def test_runs_without_error_on_long_args(django_testdir):
django_testdir.create_test_module("""
def test_this_is_a_long_message_which_caused_a_bug_when_scanning_for_manage_py_12346712341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234112341234112451234123412341234123412341234123412341234123412341234123412341234123412341234123412341234():
assert 1 + 1 == 2
""")

result = django_testdir.runpytest_subprocess('-k', 'this_is_a_long_message_which_caused_a_bug_when_scanning_for_manage_py_12346712341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234112341234112451234123412341234123412341234123412341234123412341234123412341234123412341234123412341234', 'django_project_root')
assert result.ret == 0