Skip to content

Commit b1ab663

Browse files
authored
django_find_project: add cwd as fallback always (#690)
Ref: #689
1 parent bbb8339 commit b1ab663

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

pytest_django/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ def find_django_path(args):
182182
args = map(str, args)
183183
args = [arg_to_path(x) for x in args if not x.startswith("-")]
184184

185+
cwd = pathlib.Path.cwd()
185186
if not args:
186-
args = [pathlib.Path.cwd()]
187+
args.append(cwd)
188+
elif cwd not in args:
189+
args.append(cwd)
187190

188191
for arg in args:
189192
if is_django_project(arg):

tests/test_manage_py_scan.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,44 @@ def test_foobar():
2424
assert outcomes["passed"] == 1
2525

2626

27+
@pytest.mark.django_project(project_root="django_project_root", create_manage_py=True)
28+
def test_django_project_found_with_k(django_testdir, monkeypatch):
29+
"""Test that cwd is checked as fallback with non-args via '-k foo'."""
30+
testfile = django_testdir.create_test_module(
31+
"""
32+
def test_foobar():
33+
assert True
34+
""",
35+
"sub/test_in_sub.py",
36+
)
37+
38+
monkeypatch.chdir(testfile.dirname)
39+
result = django_testdir.runpytest_subprocess("-k", "test_foobar")
40+
assert result.ret == 0
41+
42+
outcomes = result.parseoutcomes()
43+
assert outcomes["passed"] == 1
44+
45+
46+
@pytest.mark.django_project(project_root="django_project_root", create_manage_py=True)
47+
def test_django_project_found_with_k_and_cwd(django_testdir, monkeypatch):
48+
"""Cover cwd not used as fallback if present already in args."""
49+
testfile = django_testdir.create_test_module(
50+
"""
51+
def test_foobar():
52+
assert True
53+
""",
54+
"sub/test_in_sub.py",
55+
)
56+
57+
monkeypatch.chdir(testfile.dirname)
58+
result = django_testdir.runpytest_subprocess(testfile.dirname, "-k", "test_foobar")
59+
assert result.ret == 0
60+
61+
outcomes = result.parseoutcomes()
62+
assert outcomes["passed"] == 1
63+
64+
2765
@pytest.mark.django_project(project_root="django_project_root", create_manage_py=True)
2866
def test_django_project_found_absolute(django_testdir, monkeypatch):
2967
"""This only tests that "." is added as an absolute path (#637)."""

0 commit comments

Comments
 (0)