File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ # a test class is useful to hold data that we might want setup
2+ # for every test.
3+
4+
5+
6+ class TestClassExample (object ):
7+
8+ @classmethod
9+ def setup_class (cls ):
10+ """ this is run once for each class, before any tests """
11+ print ("testing class {}" .format (cls ))
12+
13+ @classmethod
14+ def teardown_class (cls ):
15+ """ this is run once for each class, after all tests """
16+ pass
17+
18+ def setup_method (self ):
19+ """ this is run before each of the test methods """
20+ self .l = list (range (20 ))
21+ self .s = "this is my test string"
22+
23+ def teardown_method (self ):
24+ """ this is run after each of the test methods """
25+ pass
26+
27+ def test_list (self ):
28+ assert len (self .l ) == 20
29+
30+ def test_string (self ):
31+ assert len (self .s .split ()) == 5
32+
33+
Original file line number Diff line number Diff line change 1+ # to run this, in this directory, simply do
2+ #
3+ # pytest .
4+
5+ def multiply (a , b ):
6+ return a * b
7+
8+ def test_multiply ():
9+ assert multiply (4 , 6 ) == 24
10+
11+ def test_multiply2 ():
12+ assert multiply (5 , 6 ) == 24
13+
You can’t perform that action at this time.
0 commit comments