https://github.com/pytest-dev/pytest
‘test_foo.py’:
# -*- coding: utf-8 -*-
from forkapi import fork
def test_voltage0():
"""Voltage Test"""
limit_min = 3.0
limit_max = 3.6
# initialize Fork instance
f = fork.Fork('192.168.0.109')
# measure voltage at AI0
measured = f.aiGet(0)
# compare measured value with the limits
# assert raises an AssertionError in case if the expression returns False
assert limit_min <= measured <= limit_max
‘test_foo.py’ (continued):
def test_voltage1():
"""Another voltage Test"""
limit_min = -3.6
limit_max = -3.3
f = fork.Fork('192.168.0.109')
# measure voltage at AI1
measured = f.aiGet(1)
# compare measured value with the limits
assert limit_min <= measured <= limit_max
def test_voltage2():
"""Yet another voltage Test"""
limit_min = 2
limit_max = 4
f = fork.Fork('192.168.0.109')
# measure voltage at AI2
measured = f.aiGet(2)
# compare measured value with the limits
assert limit_min <= measured <= limit_max
‘conftest.py’:
# -*- coding: utf-8 -*-
from forkapi import fork
import pytest
@pytest.fixture(scope='session')
def stand():
stand_ip = '192.168.0.109'
f = fork.Fork(stand_ip)
f.connect()
return f
‘test_foo.py’:
# -*- coding: utf-8 -*-
# from forkapi import fork
def test_voltage0(stand):
"""Voltage Test"""
limit_min = 3.0
limit_max = 3.6
measured = stand.aiGet(0)
assert limit_min <= measured <= limit_max
‘conftest.py’:
# -*- coding: utf-8 -*-
from forkapi import fork
import pytest
def pytest_addoption(parser):
"""Adding extra options to INI file"""
parser.addini('fork', help='FORK IP address')
...
@pytest.fixture(scope='session')
def stand(pytestconfig):
stand_ip = pytestconfig.getini('fork')
f = fork.Fork(stand_ip)
f.connect()
return f
‘pytest.ini’:
[pytest]
fork = 192.168.0.109
pip install pytest-html
addr = 0x4
data = b'\xE3
res = dev1.I2CWriteRead(addr,3,data)
pip install pytest-odering
‘test_foo.py’:
# run this test the first
@pytest.mark.run(order=1)
def test_voltage2(stand):
"""Yet another voltage Test"""
limit_min = 2
limit_max = 4
# measure voltage at AI2
measured = stand.aiGet(2)
# compare measured value with the limits
assert limit_min <= measured <= limit_max