-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_example.py
More file actions
70 lines (47 loc) · 1.42 KB
/
test_example.py
File metadata and controls
70 lines (47 loc) · 1.42 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pytest
def test_equal_or_not_equal():
assert 3 == 3
assert 3 != 1
def test_is_instance():
assert isinstance('this is a string', str)
assert not isinstance('19', int)
def test_boolean():
validated = True
assert validated is True
assert ('hello' == 'world') is False
def test_type():
assert type('Hello' is str)
assert type('world' is not int)
def test_greater_and_less_than():
assert 7 > 3
assert 4 < 10
def test_list():
num_list = [1,2,3,4,5]
any_list = [False, False]
assert 1 in num_list
assert 7 not in num_list
assert all(num_list)
assert not any(any_list)
class Student:
def __init__(self, first_name: str, last_name: str, major: str, years: int):
self.first_name = first_name
self.last_name = last_name
self.major = major
self.years = years
# def test_person_initialization():
# assert p.first_name == 'John'
# assert p.last_name == 'Doe'
# assert p.major == 'CS'
# assert p.years == 3
'''for multiple testing
we will need to create new objects
-> There comes pytest fixtures
'''
@pytest.fixture
def default_employee():
return Student('John', 'Doe', 'CS', 3)
def test_person_initialization(default_employee):
assert default_employee.first_name == 'John'
assert default_employee.last_name == 'Doe'
assert default_employee.major == 'CS'
assert default_employee.years == 3