Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rewrite pytest hooks as a class plugin#95

Merged
lysnikolaou merged 2 commits into
Quansight-Labs:mainfrom
lysnikolaou:rewrite-class-plugin
Jul 17, 2025
Merged

Rewrite pytest hooks as a class plugin#95
lysnikolaou merged 2 commits into
Quansight-Labs:mainfrom
lysnikolaou:rewrite-class-plugin

Conversation

@lysnikolaou
Copy link
Copy Markdown
Contributor

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.

  • 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.

The diff is difficult to review. It'd be easier to view the new code and go from pytest_itemcollected to _is_thread_unsafe to _mark_test_thread_unsafe. Then review the other two hoooks pytest_report_teststatus and pytest_terminal_summary.

Also, I made sure that all tests pass with only very minor changes (related to pluralization).

- 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.
@lysnikolaou lysnikolaou force-pushed the rewrite-class-plugin branch from 5dbae20 to 5491657 Compare July 12, 2025 16:34
Copy link
Copy Markdown
Collaborator

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lysnikolaou lysnikolaou merged commit 63ef3b1 into Quansight-Labs:main Jul 17, 2025
9 checks passed
@lysnikolaou lysnikolaou deleted the rewrite-class-plugin branch July 17, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants