{"id":10154,"library":"pytest-xdist-worker-stats","title":"Pytest Xdist Worker Stats","description":"pytest-xdist-worker-stats is a pytest plugin that provides detailed statistics about individual worker performance after a pytest-xdist run, including test counts and execution times. The current version is 0.4.0, and it maintains an active, moderate release cadence.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/mikicz/pytest-xdist-worker-stats","tags":["pytest","plugin","xdist","testing","performance","statistics"],"install":[{"cmd":"pip install pytest-xdist-worker-stats","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework","package":"pytest","optional":false},{"reason":"Required for parallel test execution and worker management, which this plugin extends","package":"pytest-xdist","optional":false}],"imports":[{"note":"Pytest plugins are designed for automatic discovery by pytest itself. Users typically do not need to import anything directly from 'pytest-xdist-worker-stats' in their test files or conftest.py.","symbol":"pytest-xdist-worker-stats","correct":"No direct import needed; pytest discovers plugins automatically."}],"quickstart":{"code":"import time\nimport pytest\n\n@pytest.mark.parametrize(\"i\", range(5))\ndef test_slow_task_a(i):\n    time.sleep(0.1)\n\n@pytest.mark.parametrize(\"i\", range(3))\ndef test_slow_task_b(i):\n    time.sleep(0.2)\n\n# To run: save this as test_example.py, then run from your terminal:\n# pip install pytest pytest-xdist pytest-xdist-worker-stats\n# pytest -n 2 --xdist-worker-stats test_example.py","lang":"python","description":"This quickstart demonstrates how to use `pytest-xdist-worker-stats` by creating a simple test file with parameterized tests that will be run in parallel by `pytest-xdist`. The `--xdist-worker-stats` flag will activate the plugin and display the worker statistics after the test run."},"warnings":[{"fix":"Ensure `pip install pytest-xdist` is executed and pytest is run with a parallelization flag, e.g., `pytest -n auto`.","message":"This plugin requires `pytest-xdist` to be installed and active (by using the `-n` flag with pytest) to function correctly. Without `pytest-xdist`, there are no parallel workers to report statistics for.","severity":"gotcha","affected_versions":"All"},{"fix":"Always include `--xdist-worker-stats` in your pytest command, e.g., `pytest -n auto --xdist-worker-stats`.","message":"The worker statistics are only displayed when the `--xdist-worker-stats` command-line flag is explicitly used with pytest. Simply installing the plugin is not enough.","severity":"gotcha","affected_versions":"All"},{"fix":"Always keep `pytest-xdist-worker-stats` updated alongside `pytest` and `pytest-xdist` to ensure compatibility. Check release notes for specific version requirements.","message":"Version 0.4.0 introduces support for Pytest 9. Older versions of `pytest-xdist-worker-stats` may not be compatible with Pytest 9, and conversely, newer versions might introduce incompatibilities with significantly older Pytest versions (e.g., Pytest 7 or earlier).","severity":"breaking","affected_versions":"<0.4.0 (with Pytest 9)"},{"fix":"Ensure your environment uses Python 3.10 or a more recent version. Consider using `pyenv` or `conda` to manage Python versions.","message":"The library requires Python 3.10 or newer. Running it with older Python versions will result in installation or runtime errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Pytest plugins are automatically discovered; direct imports are not typically needed. Ensure the plugin is installed via `pip install pytest-xdist-worker-stats`.","cause":"Attempting to directly import the plugin into test files or conftest.py, or the plugin is not installed.","error":"ModuleNotFoundError: No module named 'pytest_xdist_worker_stats'"},{"fix":"Verify installation by running `pip install pytest-xdist-worker-stats`. If it's installed, ensure your `pytest` command is executed within the same virtual environment where the plugin is installed.","cause":"The `pytest-xdist-worker-stats` plugin is either not installed, or pytest cannot discover it in the current environment.","error":"pytest: error: unrecognized arguments: --xdist-worker-stats"},{"fix":"Rerun your pytest command, making sure to include the flag, e.g., `pytest -n auto --xdist-worker-stats`.","cause":"The `--xdist-worker-stats` command-line flag was not included when running pytest.","error":"No worker statistics output after running tests."},{"fix":"Install the `pytest-xdist` package: `pip install pytest-xdist`.","cause":"The essential dependency `pytest-xdist` is not installed, which is required for this plugin to function and provide worker stats.","error":"Failed to load plugin 'xdist-worker-stats': <class 'ModuleNotFoundError'>: No module named 'pytest_xdist'"}]}