Closed ngoldbaum closed 2 weeks ago
Non-exhaustive list of pytest tools that are inherently not thread-safe:
capsys
fixture usage (shared sys.stdout
/sys.stderr
);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.
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.