Skip to content

Conversation

@Liam-DeVoe
Copy link
Contributor

Closes #153.

pytest_collection_finish is the right place to hook pytest for after exactly the tests we want have been selected. I don't think any pytest-run-parallel logic needs to execute for any non-selected item, so we can just wait until this stage in the process.

Note the pytest docs claim 4. Set session.items to the list of collected items comes after 3. pytest_collection_finish(session), but I'm pretty sure this is a docs bug on pytest's end, and these steps should be reversed; I'll send a PR their way.

@Liam-DeVoe
Copy link
Contributor Author

I don't think any pytest-run-parallel logic needs to execute for any non-selected item, so we can just wait until this stage in the process.

Small caveat: there's now an ordering contention between this and pytest_report_collectionfinish (see 632d3ef), so our pytest_collection_finish needs to be tryfirst=True. I think this is fine, and moreover unlikely to break anything more than the status quo, which already processed items before the user's pytest_collection_finish was called.

@ngoldbaum
Copy link
Collaborator

@nickodell would you mind trying this out for your SciPy development workflow?

@nickodell
Copy link
Contributor

@nickodell would you mind trying this out for your SciPy development workflow?

Sure, here is a quick benchmark.

This is benchmarking the test command python3.13 -P -m pytest -m 'not slow' -k test_cdf_nolan_samples --parallel-threads=2 --pyargs scipy.stats. This test command selects a single test case out of SciPy, and runs it in parallel. The actual test is very fast, so this is mostly measuring pytest and pytest-run-parallel's setup overhead.

I measured this in two ways:

  • Total time spent, using the time command in Bash to measure time.
  • Percent time spent in _is_thread_unsafe, including child functions, using py-spy to record time spent in each function.

The results are the following.

version time spent percentage of time spent in _is_thread_unsafe
0.8.0 14.180s 70.6%
gh-156 3.941s 0.6%

It is significantly faster for this use case.

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.

Don't check thread safety of deselected tests

3 participants