Skip to content

Commit c9c4e60

Browse files
committed
Add tests using test classes, see Issue #6.
1 parent 817bcca commit c9c4e60

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tests/test_03_class.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
"""Usage with test classes.
2+
"""
3+
4+
import pytest
5+
6+
7+
def test_class_simple(ctestdir):
8+
"""Simple dependencies of test methods in a class.
9+
test_a() deliberately fails, some other methods depend on it, some don't.
10+
"""
11+
ctestdir.makepyfile("""
12+
import pytest
13+
14+
class TestClass(object):
15+
16+
@pytest.mark.dependency()
17+
def test_a(self):
18+
assert False
19+
20+
@pytest.mark.dependency()
21+
def test_b(self):
22+
pass
23+
24+
@pytest.mark.dependency(depends=["test_a"])
25+
def test_c(self):
26+
pass
27+
28+
@pytest.mark.dependency(depends=["test_b"])
29+
def test_d(self):
30+
pass
31+
32+
@pytest.mark.dependency(depends=["test_b", "test_c"])
33+
def test_e(self):
34+
pass
35+
""")
36+
result = ctestdir.runpytest("--verbose")
37+
result.assert_outcomes(passed=2, skipped=2, failed=1)
38+
result.stdout.fnmatch_lines("""
39+
*::TestClass::test_a FAILED
40+
*::TestClass::test_b PASSED
41+
*::TestClass::test_c SKIPPED
42+
*::TestClass::test_d PASSED
43+
*::TestClass::test_e SKIPPED
44+
""")
45+
46+
47+
def test_class_simple_named(ctestdir):
48+
"""Mostly the same as test_class_simple(), but name the test methods
49+
now explicitely.
50+
"""
51+
ctestdir.makepyfile("""
52+
import pytest
53+
54+
class TestClassNamed(object):
55+
56+
@pytest.mark.dependency(name="a")
57+
def test_a(self):
58+
assert False
59+
60+
@pytest.mark.dependency(name="b")
61+
def test_b(self):
62+
pass
63+
64+
@pytest.mark.dependency(name="c", depends=["a"])
65+
def test_c(self):
66+
pass
67+
68+
@pytest.mark.dependency(name="d", depends=["b"])
69+
def test_d(self):
70+
pass
71+
72+
@pytest.mark.dependency(name="e", depends=["b", "c"])
73+
def test_e(self):
74+
pass
75+
""")
76+
result = ctestdir.runpytest("--verbose")
77+
result.assert_outcomes(passed=2, skipped=2, failed=1)
78+
result.stdout.fnmatch_lines("""
79+
*::TestClassNamed::test_a FAILED
80+
*::TestClassNamed::test_b PASSED
81+
*::TestClassNamed::test_c SKIPPED
82+
*::TestClassNamed::test_d PASSED
83+
*::TestClassNamed::test_e SKIPPED
84+
""")

0 commit comments

Comments
 (0)