Get -nauto default from PYTEST_XDIST_AUTO_NUM_WORKERS (#829)

* Get `-nauto` default from `PYTEST_XDIST_AUTO_NUM_WORKERS`

A few additional tests for existing functionality are added too.
And the ``-n logical`` option is documented.

Fixes: https://github.com/pytest-dev/pytest-xdist/issues/792
This commit is contained in:
Petr Viktorin
2022-10-24 14:33:19 +02:00
committed by GitHub
parent ab95a4b45d
commit c168706fbe
5 changed files with 155 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
import os
import uuid
import sys
import warnings
import pytest
@@ -12,6 +13,13 @@ _sys_path = list(sys.path) # freeze a copy of sys.path at interpreter startup
@pytest.hookimpl
def pytest_xdist_auto_num_workers(config):
env_var = os.environ.get("PYTEST_XDIST_AUTO_NUM_WORKERS")
if env_var:
try:
return int(env_var)
except ValueError:
warnings.warn("PYTEST_XDIST_AUTO_NUM_WORKERS is not a number: {env_var!r}. Ignoring it.")
try:
import psutil
except ImportError: