File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ import mock
4+ import pytest
5+ from tools import SMBusFakeDevice
6+
7+
8+ @pytest .fixture ()
9+ def smbus_not_present ():
10+ sys .modules ['smbus2' ] = mock .MagicMock ()
11+ yield sys .modules ['smbus2' ]
12+ del sys .modules ['smbus2' ]
13+
14+
15+ @pytest .fixture ()
16+ def smbus ():
17+ sys .modules ['smbus2' ] = mock .MagicMock ()
18+ sys .modules ['smbus2' ].SMBus = SMBusFakeDevice
19+ yield sys .modules ['smbus2' ]
20+ del sys .modules ['smbus2' ]
21+
22+
23+ @pytest .fixture ()
24+ def LSM303D ():
25+ from lsm303d import LSM303D
26+ yield LSM303D
27+ del sys .modules ['lsm303d' ]
Original file line number Diff line number Diff line change 1- import sys
2-
3- import mock
41import pytest
52
63
7- def test_setup_not_present ():
8- sys .modules ['smbus' ] = mock .MagicMock ()
9- from lsm303d import LSM303D
4+ def test_setup_not_present (smbus_not_present , LSM303D ):
105 lsm303d = LSM303D ()
116 with pytest .raises (RuntimeError ):
127 lsm303d .setup ()
138
149
15- def test_setup_mock_present ():
16- from tools import SMBusFakeDevice
17- smbus = mock .Mock ()
18- smbus .SMBus = SMBusFakeDevice
19- sys .modules ['smbus' ] = smbus
20- from lsm303d import LSM303D
10+ def test_setup_mock_present (smbus , LSM303D ):
2111 lsm303d = LSM303D ()
2212 lsm303d .setup ()
You can’t perform that action at this time.
0 commit comments