{"id":21810,"library":"pytest-run-parallel","title":"pytest-run-parallel","description":"A pytest plugin to run tests concurrently using threads. It automatically detects thread-unsafe tests (e.g., using fixtures like tmp_path, monkeypatch, capsys, or mocking) and marks them as serial. Version 0.8.2 supports Python >=3.9. Releases are intermittent.","status":"active","version":"0.8.2","language":"python","source_language":"en","source_url":"https://github.com/Quansight-Labs/pytest-run-parallel","tags":["pytest","testing","parallel","threads","concurrency"],"install":[{"cmd":"pip install pytest-run-parallel","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"This is a pytest plugin; it's auto-discovered when installed. No explicit import needed in conftest.","wrong":"import pytest_run_parallel","symbol":"pytest_run_parallel","correct":"pytest_plugins = ['pytest_run_parallel']"}],"quickstart":{"code":"# In your project root, run:\npytest --parallel-threads=auto\n# Or set a fixed number:\npytest --parallel-threads=4\n# To detect thread-unsafe tests (default on):\npytest --parallel-threads=auto --detect-thread-unsafe\n","lang":"python","description":"Run pytest with parallel threads. The plugin automatically parallelizes tests unless they are detected as thread-unsafe."},"warnings":[{"fix":"To force parallelism on a test that uses thread-unsafe fixtures, mark it with @pytest.mark.parallel. However, this may cause flaky tests.","message":"The plugin automatically detects thread-unsafe patterns (fixtures like tmp_path, monkeypatch, capsys, etc.). If your test uses these, it will run serially, even with --parallel-threads. No explicit mark needed.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"If you rely on gc.collect in tests, they will now run serially unless you use --disable-thread-unsafe-detection or mark them as parallel.","message":"In v0.8.0, the --parallel-threads-limit mark was added. Before that, you could only set global parallelism. Also, gc.collect detection was added in v0.8.0, marking tests using gc.collect as thread-unsafe.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Avoid using --forever with pytest-xdist. Use --parallel-threads instead for parallel execution.","message":"The --forever flag interaction with pytest-xdist changed in v0.7.1. The flag may not work as expected when used with xdist.","severity":"deprecated","affected_versions":">=0.7.1"},{"fix":"If you know your mock usage is safe, you can disable detection with --disable-thread-unsafe-detection, but be careful about race conditions.","message":"Tests that use unittest.mock or fixtures like monkeypatch are automatically detected as thread-unsafe and run serially. This includes MagicMock, patch, etc.","severity":"gotcha","affected_versions":">=0.4.3"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Remove any explicit imports of pytest_run_parallel. The plugin is auto-discovered when installed.","cause":"Trying to import the plugin directly instead of relying on pytest's plugin discovery.","error":"AttributeError: module 'pytest_run_parallel' has no attribute '...'"},{"fix":"Use --parallel-threads=N where N is an integer, or use 'auto' (supported since v0.5.0).","cause":"Using --parallel-threads with a value that cannot be parsed as integer (e.g., --parallel-threads=auto without proper string handling in older versions).","error":"TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'"},{"fix":"Ensure pytest-run-parallel is installed in the current environment (pip install pytest-run-parallel).","cause":"The plugin is not installed or not enabled.","error":"pytest: error: unrecognized arguments: --parallel-threads"},{"fix":"Reduce the number of parallel threads. Use a sane value like 4 or 'auto'.","cause":"The --parallel-threads value is too high for the system (e.g., >1000).","error":"RuntimeError: cannot start new thread"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}