-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
pytest thread safety should be better documented #12356
Comments
pytest in its entirety is not intended to be thread-safe IIRC. |
pytest.warns is implemented in terms of the stdlib catch-warnings helper - which is inherently not threadsave |
TIL Best to avoid using pytest constructs inside a thread, then. This fact could be emphasized more in the docs, I don't see any mention of threads at all besides the discussion about unhandled exceptions. |
Yes, I noted that in the issue description. The issue is a request for that fact to be noted in the docs, like the docs for the stdlib helper, if making it thread safe is out of scope for the library. |
Makes sense to note somewhere that pytest's constructs/helpers are not thread safe. If somebody wants to take a look and update the docs, would love to review a PR. 👍 |
pytest.warns
is not thread safe
pip list
from the virtual environment you are usingpytest.warns
is a subclass of the standard librarywarnings.catch_warnings
context manager, which is not thread safe (this is noted in the docs).If it's not possible for pytest to have a thread-safe version, it would be nice if the docs for
pytest.warns
could note that it's implemented usingwarnings.catch_warnings
and is not thread safe for the same reason.pytest 8.2.1 on MacOS Sonoma.
Fails about 10-20% of the time on my machine:
The text was updated successfully, but these errors were encountered: