-
Notifications
You must be signed in to change notification settings - Fork 96
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
Fix random failures with parallel CLI tests #831
Conversation
The addition of capsys.disabled calls to the CLI tests was done to work around an issue with files being opened and closed in the CLI setup fixtures. When running under high parallelism the CLI tests would occasionally be split up across worker instances, and so the file system operations - which were effectively creating and removing the same file - would cause failures due to race conditions between the different test runner fixture executions. Adding capsys.disabled didn't solve this problem, it merely made it somewhat less likely to occur, and ultimately replaced the error with a different one (file not found). This commit removes the capsys.disabled calls in favor of a follow-up to stop doing all of this filesystem manipulation.
We use pytest-xdist for parallel test execution, which means multiple worker threads fire up tests which are loosely grouped by class/module. Unfortunately, there are no guarantees around any of this, so the CLI tests, which are all in one module, may execute on different workers. We had a bad fixture layout on the CLI tests which would touch a file in the CLI directory and then unlink it after the test was done. If every test ran on the same worker this was fine - only one test would ever be accessing this path location at a time. But when the tests get split across workers bad things happen with FileNotFound and things of that nature. This change moves us off of having multiple tests creating and destroying the same file in the same file path location, instead relying on a fixed file that already exists in a static location in the repository.
Current dependencies on/for this PR: This stack of pull requests is managed by Graphite. |
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
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.
Ahh thanks for resolving this!! Thought I had something wrong with my local setup that was causing these errors 🫠
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.
I was wondering about that issue - thanks for the fix!
We use pytest-xdist for parallel test execution, which means multiple
worker threads fire up tests which are loosely grouped by class/module.
Unfortunately, there are no guarantees around any of this, so the CLI
tests, which are all in one module, may execute on different workers.
We had a bad fixture layout on the CLI tests which would touch a file
in the CLI directory and then unlink it after the test was done. If
every test ran on the same worker this was fine - only one test would
ever be accessing this path location at a time. But when the tests get
split across workers bad things happen with FileNotFound and things
of that nature.
This change moves us off of having multiple tests creating and
destroying the same file in the same file path location, instead
relying on a fixed file that already exists in a static location in
the repository.