Skip to content
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

Add discussion of pytest thread safety #92

Closed
ngoldbaum opened this issue Oct 10, 2024 · 1 comment · Fixed by #96
Closed

Add discussion of pytest thread safety #92

ngoldbaum opened this issue Oct 10, 2024 · 1 comment · Fixed by #96
Labels
documentation Improvements or additions to documentation

Comments

@ngoldbaum
Copy link
Collaborator

Pytest isn't thread safe and it can be confusing if people expect it to be. We should document this.

Also similarly, the warnings module as a whole isn't thread safe. Temporary directories with named files or directories also have thread safety issues since they're using global state via the file system.

@ogrisel
Copy link

ogrisel commented Oct 10, 2024

Non-exhaustive list of pytest tools that are inherently not thread-safe:

  • the capsys fixture usage (shared sys.stdout/sys.stderr);
  • the monkeypatch fixture (and another monkeypatching tool, e.g. from unittest.mock);
  • pytest.warns (because the warnings module is not safe by itself).

Usage of the tmpdir and tmp_path fixture is currently not thread-safe. However, they could probably be thread safe if the temporary folder they create for each test would be created and deleted within the same thread as the thread used to run them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants