X Tutup
Skip to content

Commit cd3d366

Browse files
committed
some examples
1 parent 5b656ca commit cd3d366

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+

0 commit comments

Comments
 (0)
X Tutup