forked from AdaGold/hello-books-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fixtures.py
45 lines (34 loc) · 959 Bytes
/
test_fixtures.py
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
import pytest
from app import create_app
from app import db
@pytest.fixture#first add
def empty_list():
return []
def test_len_of_empty_list(empty_list):
assert isinstance(empty_list, list)
assert len(empty_list) == 0
@pytest.fixture#second part
def one_item(empty_list):
empty_list.append("item")
return empty_list
def test_len_of_unary_list(one_item):
assert isinstance(one_item, list)
assert len(one_item) == 1
assert one_item[0] == "item"
class FancyObject:#third add
def __init__(self):
self.fancy = True
print(f"\nFancyObject: {self.fancy}")
def or_is_it(self):
self.fancy = not self.fancy
def cleanup(self):
print(f"\ncleanup: {self.fancy}")
@pytest.fixture
def so_fancy():
fancy_object = FancyObject()
yield fancy_object
fancy_object.cleanup()
def test_so_fancy(so_fancy):
assert so_fancy.fancy
so_fancy.or_is_it()
assert not so_fancy.fancy