File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+
4
+ class TestClass (object ):
5
+
6
+ @pytest .mark .dependency ()
7
+ @pytest .mark .xfail (reason = "deliberate fail" )
8
+ def test_a (self ):
9
+ assert False
10
+
11
+ @pytest .mark .dependency ()
12
+ def test_b (self ):
13
+ pass
14
+
15
+ @pytest .mark .dependency (depends = ["test_a" ])
16
+ def test_c (self ):
17
+ pass
18
+
19
+ @pytest .mark .dependency (depends = ["test_b" ])
20
+ def test_d (self ):
21
+ pass
22
+
23
+ @pytest .mark .dependency (depends = ["test_b" , "test_c" ])
24
+ def test_e (self ):
25
+ pass
26
+
27
+
28
+ class TestClassNamed (object ):
29
+
30
+ @pytest .mark .dependency (name = "a" )
31
+ @pytest .mark .xfail (reason = "deliberate fail" )
32
+ def test_a (self ):
33
+ assert False
34
+
35
+ @pytest .mark .dependency (name = "b" , depends = ["a" ])
36
+ def test_b (self ):
37
+ pass
38
+
39
+ @pytest .mark .dependency (name = "c" )
40
+ def test_c (self ):
41
+ pass
42
+
43
+ @pytest .mark .dependency (name = "d" , depends = ["c" ])
44
+ def test_d (self ):
45
+ pass
46
+
47
+ @pytest .mark .dependency (name = "e" , depends = ["b" , "c" ])
48
+ def test_e (self ):
49
+ pass
Original file line number Diff line number Diff line change 49
49
50
50
.. _usage-parametrized :
51
51
52
+ Using test classes
53
+ ------------------
54
+
55
+ Tests may be grouped in classes in pytest. Marking the dependencies
56
+ of methods in test classes works the same way as for simple test
57
+ functions. In the following example we define two test classes. Each
58
+ works in the same manner as the previous examples respectively:
59
+
60
+ .. literalinclude :: ../examples/testclass.py
61
+
62
+ In `TestClass ` the default names for the tests are used, which is the
63
+ name of the respective method in this case, while in `TestClassNamed `
64
+ these names are overridden an explicit name argument to the
65
+ :func: `pytest.mark.dependency ` marker.
66
+
52
67
Parametrized tests
53
68
------------------
54
69
You can’t perform that action at this time.
0 commit comments