Skip to content

Commit 79fce26

Browse files
committed
Support parameterized expasion with "*"
If a depends string contains "*" replace it with "[" and match all the tests that contain that string. Check to ensure all of those tests passed
1 parent e67cac5 commit 79fce26

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

pytest_dependency.py

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ def checkDepend(self, depends, item):
7575
if i in self.results:
7676
if self.results[i].isSuccess():
7777
continue
78+
elif "*" in i:
79+
# Replace "*" with "[" then search the results for any
80+
# matches in the results, this should catch parameterized
81+
# tests
82+
dep = i.replace("*", "[")
83+
dep_list = [x for x in self.results if dep in x]
84+
if dep_list:
85+
# Check the depends list to ensure they all passed
86+
if all(self.results[x].isSuccess() for x in dep_list):
87+
continue
7888
else:
7989
if _ignore_unknown:
8090
continue

tests/test_03_param.py

+41
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,44 @@ def test_c(w):
5353
*::test_c?2? SKIPPED
5454
*::test_c?3? PASSED
5555
""")
56+
57+
def test_auto_param_expand(ctestdir):
58+
ctestdir.makepyfile("""
59+
import pytest
60+
61+
@pytest.mark.parametrize("x", [0,1])
62+
@pytest.mark.dependency()
63+
def test_a(x):
64+
pass
65+
66+
@pytest.mark.parametrize("x", [0,1])
67+
@pytest.mark.dependency()
68+
def test_b(x):
69+
assert x == 0
70+
71+
@pytest.mark.dependency(depends=["test_a*"])
72+
def test_c():
73+
pass
74+
75+
@pytest.mark.dependency(depends=["test_b*"])
76+
def test_d():
77+
pass
78+
79+
@pytest.mark.dependency(depends=["test_null*"])
80+
def test_e():
81+
pass
82+
83+
""")
84+
85+
result = ctestdir.runpytest("--verbose")
86+
result.assert_outcomes(passed=4, skipped=2, failed=1)
87+
print(result.stdout)
88+
result.stdout.fnmatch_lines("""
89+
*::test_a?0? PASSED
90+
*::test_a?1? PASSED
91+
*::test_b?0? PASSED
92+
*::test_b?1? FAILED
93+
*::test_c PASSED
94+
*::test_d SKIPPED
95+
*::test_e SKIPPED
96+
""")

0 commit comments

Comments
 (0)