Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

justinb4003
Copy link

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.

@virtuald
Copy link
Member

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.

@justinb4003
Copy link
Author

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('.')
Copy link
Member

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.

@auscompgeek auscompgeek linked an issue Jan 1, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

pyfrc tests don't work with pytest-xdist
2 participants