forked from RKrahl/pytest-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_03_param.py
89 lines (76 loc) · 2.88 KB
/
test_03_param.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""A scenario featuring parametrized tests.
"""
import pytest
def test_simple_params(ctestdir):
"""Simple test for a dependency on a parametrized test.
This example has been used in the discussion of PR #43.
"""
ctestdir.makepyfile("""
import pytest
_md = pytest.mark.dependency
@pytest.mark.parametrize("x", [ 0, 1 ])
@pytest.mark.dependency()
def test_a(x):
assert x == 0
@pytest.mark.parametrize("x", [
pytest.param(0, marks=_md(depends=["test_a[0]"])),
pytest.param(1, marks=_md(depends=["test_a[1]"])),
])
def test_b(x):
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=2, skipped=1, failed=1)
result.stdout.re_match_lines(r"""
.*::test_a\[0\] PASSED
.*::test_a\[1\] FAILED
.*::test_b\[0\] PASSED
.*::test_b\[1\] SKIPPED(?:\s+\(.*\))?
""")
def test_multiple(ctestdir):
ctestdir.makepyfile("""
import pytest
_md = pytest.mark.dependency
@pytest.mark.parametrize("x,y", [
pytest.param(0, 0, marks=_md(name="a1")),
pytest.param(0, 1, marks=_md(name="a2")),
pytest.param(1, 0, marks=_md(name="a3")),
pytest.param(1, 1, marks=_md(name="a4"))
])
def test_a(x,y):
assert x==0 or y==0
@pytest.mark.parametrize("u,v", [
pytest.param(1, 2, marks=_md(name="b1", depends=["a1", "a2"])),
pytest.param(1, 3, marks=_md(name="b2", depends=["a1", "a3"])),
pytest.param(1, 4, marks=_md(name="b3", depends=["a1", "a4"])),
pytest.param(2, 3, marks=_md(name="b4", depends=["a2", "a3"])),
pytest.param(2, 4, marks=_md(name="b5", depends=["a2", "a4"])),
pytest.param(3, 4, marks=_md(name="b6", depends=["a3", "a4"]))
])
def test_b(u,v):
pass
@pytest.mark.parametrize("w", [
pytest.param(1, marks=_md(name="c1", depends=["b1", "b3", "b5"])),
pytest.param(2, marks=_md(name="c2", depends=["b1", "b3", "b6"])),
pytest.param(3, marks=_md(name="c3", depends=["b1", "b2", "b4"]))
])
def test_c(w):
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=7, skipped=5, failed=1)
result.stdout.re_match_lines(r"""
.*::test_a\[0-0\] PASSED
.*::test_a\[0-1\] PASSED
.*::test_a\[1-0\] PASSED
.*::test_a\[1-1\] FAILED
.*::test_b\[1-2\] PASSED
.*::test_b\[1-3\] PASSED
.*::test_b\[1-4\] SKIPPED(?:\s+\(.*\))?
.*::test_b\[2-3\] PASSED
.*::test_b\[2-4\] SKIPPED(?:\s+\(.*\))?
.*::test_b\[3-4\] SKIPPED(?:\s+\(.*\))?
.*::test_c\[1\] SKIPPED(?:\s+\(.*\))?
.*::test_c\[2\] SKIPPED(?:\s+\(.*\))?
.*::test_c\[3\] PASSED
""")