Skip to content

Commit 11b0560

Browse files
committed
QA: Update tests.
1 parent fdc7835 commit 11b0560

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

tests/conftest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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']

tests/test_setup.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import sys
2-
3-
import mock
41
import 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()

0 commit comments

Comments
 (0)