Skip to content

Commit ad04078

Browse files
authored
MNT Avoid pytest warnings when pytest-run-parallel is not installed (#32088)
1 parent 4976c12 commit ad04078

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sklearn/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
sp_version,
3838
)
3939

40+
try:
41+
import pytest_run_parallel # noqa:F401
42+
43+
PARALLEL_RUN_AVAILABLE = True
44+
except ImportError:
45+
PARALLEL_RUN_AVAILABLE = False
46+
47+
4048
try:
4149
from scipy_doctest.conftest import dt_config
4250
except ModuleNotFoundError:
@@ -317,6 +325,11 @@ def pytest_generate_tests(metafunc):
317325
metafunc.parametrize("global_random_seed", random_seeds)
318326

319327

328+
def pytest_addoption(parser, pluginmanager):
329+
if not PARALLEL_RUN_AVAILABLE:
330+
parser.addini("thread_unsafe_fixtures", "list of stuff")
331+
332+
320333
def pytest_configure(config):
321334
# Use matplotlib agg backend during the tests including doctests
322335
try:
@@ -346,6 +359,25 @@ def pytest_configure(config):
346359
faulthandler.enable()
347360
faulthandler.dump_traceback_later(faulthandler_timeout, exit=True)
348361

362+
if not PARALLEL_RUN_AVAILABLE:
363+
config.addinivalue_line(
364+
"markers",
365+
"parallel_threads(n): run the given test function in parallel "
366+
"using `n` threads.",
367+
)
368+
config.addinivalue_line(
369+
"markers",
370+
"thread_unsafe: mark the test function as single-threaded",
371+
)
372+
config.addinivalue_line(
373+
"markers",
374+
"iterations(n): run the given test function `n` times in each thread",
375+
)
376+
config.addinivalue_line(
377+
"markers",
378+
"iterations(n): run the given test function `n` times in each thread",
379+
)
380+
349381

350382
@pytest.fixture
351383
def hide_available_pandas(monkeypatch):

0 commit comments

Comments
 (0)