-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pytest.py
More file actions
50 lines (32 loc) · 884 Bytes
/
Copy pathtest_pytest.py
File metadata and controls
50 lines (32 loc) · 884 Bytes
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
import pytest
@pytest.fixture
def setup_math():
import math
return math
@pytest.fixture
def setup_function(request):
def teardown_function():
print("teardown_function called")
request.addfinalizer(teardown_function)
print("setup_function called")
def test_func(setup_function):
print('Test_Func called')
def test_setup_math(setup_math):
assert setup_math.pow(2, 3) == 8
class TestClass(object):
def test_in(self):
assert 'h' in 'hello'
def test_two(self, setup_math):
assert setup_math.ceil(10) == 10
def raise_exit():
raise SystemExit(1)
def test_mytest():
with pytest.raises(SystemExit):
raise_exit()
@pytest.mark.parametrize('test_input,expected', [
('1+1', 2),
('2*10', 20),
# ('1==1', False),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected