Rewrite pytest hooks as a class plugin#95
Merged
lysnikolaou merged 2 commits intoJul 17, 2025
Conversation
- Instead of trying to figure out the thread-unsafe tests in each step (or the ones that were actually run in parallel), keep a record of all tests in `self.thread_unsafe` and `self.run_in_parallel`. Both are `dicts` with the node ID as key. In `self.thread_unsafe` the values are the reason, while in `self.run_in_parallel` the number of parallel threads the test was run in. - Break down pytest_itemcollected in more functions that are easier to understand. `_is_thread_unsafe` does the various thread unsafety checks and marks the tests as thread unsafe using `_mark_test_thread_unsafe`. - Now, tests without an `obj` object and doctests are marked as thread-unsafe and a reason is output. - `pytest_report_teststatus` and `pytest_terminal_summary` use the new dicts, which makes them much simpler. - Correctly pluralize test report.
5dbae20 to
5491657
Compare
ngoldbaum
approved these changes
Jul 13, 2025
Collaborator
ngoldbaum
left a comment
There was a problem hiding this comment.
I agree, this is easier to understand. Thanks for the cleanup! Leaving it open in case anyone else wants to take a look since it’s Saturday.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quite some stuff here. Had some free time during the weekend, so I though I could make the plugin simpler and much easier to work on.
self.thread_unsafeandself.run_in_parallel. Both aredictswith the node ID as key. Inself.thread_unsafethe values are the reason, while inself.run_in_parallelthe number of parallel threads the test was run in._is_thread_unsafedoes the various thread unsafety checks and marks the tests as thread unsafe using_mark_test_thread_unsafe.objobject and doctests are marked as thread-unsafe and a reason is output.pytest_report_teststatusandpytest_terminal_summaryuse the new dicts, which makes them much simpler.The diff is difficult to review. It'd be easier to view the new code and go from
pytest_itemcollectedto_is_thread_unsafeto_mark_test_thread_unsafe. Then review the other two hoookspytest_report_teststatusandpytest_terminal_summary.Also, I made sure that all tests pass with only very minor changes (related to pluralization).