I am trying to parallelize hardware tests across several identical devices, each with its own COM-port. Ideally, I would like each pytest-xdist worker to know which port, and thus, device, that it has access to, so that each process would only execute its own share of the tests on a single port that doesn't change during the execution of the entire test suite. I don't yet have an idea for implementing this.
-
If the ports will remain static during testing then why not just pass them in via pytest options? – Teejay Bruno Mar 15 '23 at 15:36
1 Answers
The solution I went with was to use the fact that conftest.py can be used to overwrite fixtures in pytest together with some metaprogramming:
Ceate a file with the definitions of your devices (labels, comports, etc.), then,create a subfolder per device and copy your test suites inside.
Create a copy of your main conftest.py at the top level of each device's directory, use metaprogramming to replace the variables needed by the fixtures inside your conftest.py to use the device's parameters.
Add an __init__.py
to the top level of the device's test suite to turn it into a package and scope your fixtures to 'package' level.
Finally add the xdist mark to your tests with group
set to your device's unique label.
Hope this helps anyone who might encounter a similar issue.

- 49
- 6