Skip to content

Commit 4a06661

Browse files
committed
Testing without dependencies
1 parent 424b110 commit 4a06661

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

apps/py/ch09_testing/test_lib.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
from typing import List
2+
13
import lib
4+
import pytest_mock
5+
# noinspection PyUnresolvedReferences
26
from test_fixtures import guitar_data
37

48

@@ -13,8 +17,23 @@ def test_something():
1317
# assert all(g.style == style for g in guitars)
1418

1519

16-
def test_electric_guitars(guitar_data):
20+
def test_electric_guitars(guitar_data: List[lib.Guitar], mocker: pytest_mock.MockFixture):
21+
mocker.patch('lib.get_guitars_from_db', autospec=True, return_value=guitar_data)
22+
mocker.patch('lib.log', autospec=True)
23+
1724
style = 'electric'
1825
guitars = lib.all_guitars(style)
1926
# sweet little generator expression
2027
assert all(g.style == style for g in guitars)
28+
29+
30+
def test_all_guitars(guitar_data: List[lib.Guitar], mocker: pytest_mock.MockFixture):
31+
mocker.patch('lib.get_guitars_from_db', autospec=True, return_value=guitar_data)
32+
mocker.patch('lib.log', autospec=True)
33+
34+
style = 'all'
35+
guitars = lib.all_guitars(style)
36+
# sweet little generator expression
37+
types = {g.style for g in guitars}
38+
39+
assert types == {'acoustic', 'electric'}

0 commit comments

Comments
 (0)