-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pytest-xdist to isolate tests #236
base: main
Are you sure you want to change the base?
Conversation
pytest-xdist seems like a good solution to this problem, thanks for taking a look at this. Have you considered putting the configuration either in https://github.com/robotpy/pyfrc/blob/main/pyfrc/test_support/pytest_plugin.py or forcing loading the pytest-xdist plugin at https://github.com/robotpy/pyfrc/blob/main/pyfrc/mains/cli_test.py#L117 instead? If we could make this work without users needing to add something to their test directory, that would be ideal. |
I will take a look at that! I didn't like having to touch the robot 'tests' directory either. |
from pyfrc.test_support.pytest_plugin import PyFrcPlugin | ||
# Tests are always run from the top directory of the robot project | ||
# so the location of robot.py should be the current working directory | ||
sys.path.append('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I hadn't noticed that you updated the PR.
This is a bad idea because cli_test can be imported at other times via the robotpy CLI. It would be better to get the robot path from _run_test and pass the configuration to the pytest plugin. Does pytest-xdist not have a way to propagate configuration to workers?
Additionally, the robot class doesn't have to be called MyRobot, see the logic at https://github.com/robotpy/robotpy-cli/blob/main/robotpy/main.py#L28
An alternative solution would be to set an environment variable and use that to get the robot path and class name.
This was built from the 2024.0.1 tag as I had robot code compliant with that exhibiting problems during tests due to CANId reuse between them and vendor code not releasing them.