Using Binho with Pytest
from binhoHostAdapter import binhoHostAdapter
from binhoHostAdapter import binhoUtilities
import pytest
def pytest_addoption(parser):
parser.addoption(
"--dutID", action="store", default="0xc59bb495504e5336362e3120ff032d2c", help="dutID: the GUID of the device to perform the test on"
)
parser.addoption(
"--fixtureID", action="store", default="0xa917ec725150464a39202020ff172123", help="fixtureID: the GUID of the test fixture device"
)
@pytest.fixture(scope="session")
def dut(request):
# enter the deviceID of target test device
binho_test_deviceID = request.config.getoption('--dutID')
utilities = binhoUtilities.binhoUtilities()
binhoTesterCommPorts = utilities.getPortByDeviceID(binho_test_deviceID)
binhoTesterCommPort = 0
if len(binhoTesterCommPorts) == 0:
print("ERROR: No Binho Tester Device found!")
exit(1)
elif len(binhoTesterCommPorts) > 1:
print("ERROR: More than one Binho Tester Device found!")
exit(1)
else:
binhoTesterCommPort = binhoTesterCommPorts[0]
print("Found Binho Tester Device on " + binhoTesterCommPort)
print("Opening " + binhoTesterCommPort + "...")
print
# create the binhoHostAdapter object
testDevice = binhoHostAdapter.binhoHostAdapter(binhoTesterCommPort)
print("Connecting to binho host adapter tester...")
print
def teardown():
#print('--test device teardown')
testDevice.close()
request.addfinalizer(teardown)
return testDevice
@pytest.fixture(scope="session")
def testFixture(request):
# enter the deviceID of target test device
binho_test_deviceID = request.config.getoption('--fixtureID')
utilities = binhoUtilities.binhoUtilities()
binhoTesterCommPorts = utilities.getPortByDeviceID(binho_test_deviceID)
binhoTesterCommPort = 0
if len(binhoTesterCommPorts) == 0:
print("ERROR: No Binho Tester Device found!")
exit(1)
elif len(binhoTesterCommPorts) > 1:
print("ERROR: More than one Binho Tester Device found!")
exit(1)
else:
binhoTesterCommPort = binhoTesterCommPorts[0]
print("Found Binho Tester Device on " + binhoTesterCommPort)
print("Opening " + binhoTesterCommPort + "...")
print
# create the binhoHostAdapter object
testDevice = binhoHostAdapter.binhoHostAdapter(binhoTesterCommPort)
print("Connecting to binho host adapter tester...")
print
def teardown():
#print('--test device teardown')
testDevice.close()
request.addfinalizer(teardown)
return testDevice
Last updated
Was this helpful?

