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.
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
Support free-threaded Python 3.13 #925
Support free-threaded Python 3.13 #925
Changes from 8 commits
87257a2
fb0606b
b7f6fbd
f0f4c17
95d99e1
9f49f5a
b557966
1a26622
7465f54
46fa817
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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'll be honest, I'm really struggling to understand the pytest-run-parallel docs on what this marker does.
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.
Right now I'm setting
--parallel-threads=10
in the call to pytest in tox. WIth that setting, for each test, pytest-run-parallel creates a thread pool that, by default, simultaneously executes every test in the test suite in 10 threads.pytest-run-parallel
also additionally lets you repeatedly run the test for a number ofiterations
in each spawned thread. By default it runs the test once in each thread. I'm not using that feature in this PR.The
pytest.mark.parallel_threads(1)
decorator overrides the global default we're setting in the tox call topytest
and tellspytest-run-parallel
to spawn a single thread for this test. I'm also not overriding the defaultiterations
, so it runs the test once, just like ifpytest-run-parallel
wasn't turned on in the test session.I think the
pytest-run-parallel
docs might be clearer if the readme included some example code usingconcurrent.futures.ThreadPoolExecutor
that is equivalent to whatpytest-run-parallel
is doing. Thanks for the feedback that the docs are unclear.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.
Ok. I'm now following.
pytest-run-parallel
's behavior is not what I expected based on either its name or reading the README. What I thought it was doing was running all the tests in parallel, whereas what it's actually doing is running each test multiple times in parallel with itself.Based on this, I think I'd actually recommend dropping
pytest-run-parallel
and simply having onlytest_multithreading
, which exercises the same behavior in a much clearer way. (Seperately, I'd love it if pytest had in-process test parallelism).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.
Maybe free-threaded Python will change things, but making pytest truly thread safe would be a really big undertaking. I suspect someone will try in the next year or two, or maybe try writing a thread-safe pytest-compatible test runner. Either way - big undertaking!
What does work is to spawn threads inside each test, but not share any of the Pytest testing primitives between threads. This is more-or-less what pytest-run-parallel is doing. This works doing one test at a time, but actually running multiple tests (which might share marks and fixtures) will probably lead to bad times.
All that said - separate from performance and concurrency, I think it would be really useful to run multiple tests simultaneously to discover races and use of global state. I found several novel races in CPython working on PyO3 because cargo runs tests simultaneously in a thread pool.
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 chose these parameters to make this run in a reasonable time. Still, it's a very slow test compared with the rest of the test suite.
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.
This comment no longer makes a ton of sense
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 don't think we need a user class at all, just a function that returns a tuple of values.