Skip to content

Commit ec51ff8

Browse files
voidusblueyed
authored andcommitted
Avoid crash after OSError during django path detection (#664)
Fixes #662
1 parent 5000ff8 commit ec51ff8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pytest_django/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ def _handle_import_error(extra_message):
120120

121121
def _add_django_project_to_path(args):
122122
def is_django_project(path):
123-
return path.is_dir() and (path / 'manage.py').exists()
123+
try:
124+
return path.is_dir() and (path / 'manage.py').exists()
125+
except OSError:
126+
return False
124127

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

135137
if not args:
136138
args = [pathlib.Path.cwd()]

tests/test_manage_py_scan.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ def test_django_project_found_invalid_settings_version(django_testdir, monkeypat
8383
result = django_testdir.runpytest_subprocess('django_project_root', '--help')
8484
assert result.ret == 0
8585
result.stdout.fnmatch_lines(['*usage:*'])
86+
87+
88+
@pytest.mark.django_project(project_root='django_project_root',
89+
create_manage_py=True)
90+
def test_runs_without_error_on_long_args(django_testdir):
91+
django_testdir.create_test_module("""
92+
def test_this_is_a_long_message_which_caused_a_bug_when_scanning_for_manage_py_12346712341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234112341234112451234123412341234123412341234123412341234123412341234123412341234123412341234123412341234():
93+
assert 1 + 1 == 2
94+
""")
95+
96+
result = django_testdir.runpytest_subprocess('-k', 'this_is_a_long_message_which_caused_a_bug_when_scanning_for_manage_py_12346712341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234123412341234112341234112451234123412341234123412341234123412341234123412341234123412341234123412341234123412341234', 'django_project_root')
97+
assert result.ret == 0

0 commit comments

Comments
 (0)