Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/scipy/conftest.py @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 # Pytest customization | |
2 import os | |
3 import pytest | |
4 import warnings | |
5 | |
6 import numpy as np | |
7 import numpy.testing as npt | |
8 from scipy._lib._fpumode import get_fpu_mode | |
9 from scipy._lib._testutils import FPUModeChangeWarning | |
10 from scipy._lib import _pep440 | |
11 | |
12 | |
13 def pytest_configure(config): | |
14 config.addinivalue_line("markers", | |
15 "slow: Tests that are very slow.") | |
16 config.addinivalue_line("markers", | |
17 "xslow: mark test as extremely slow (not run unless explicitly requested)") | |
18 config.addinivalue_line("markers", | |
19 "xfail_on_32bit: mark test as failing on 32-bit platforms") | |
20 try: | |
21 import pytest_timeout # noqa:F401 | |
22 except Exception: | |
23 config.addinivalue_line( | |
24 "markers", 'timeout: mark a test for a non-default timeout') | |
25 | |
26 | |
27 def _get_mark(item, name): | |
28 if _pep440.parse(pytest.__version__) >= _pep440.Version("3.6.0"): | |
29 mark = item.get_closest_marker(name) | |
30 else: | |
31 mark = item.get_marker(name) | |
32 return mark | |
33 | |
34 | |
35 def pytest_runtest_setup(item): | |
36 mark = _get_mark(item, "xslow") | |
37 if mark is not None: | |
38 try: | |
39 v = int(os.environ.get('SCIPY_XSLOW', '0')) | |
40 except ValueError: | |
41 v = False | |
42 if not v: | |
43 pytest.skip("very slow test; set environment variable SCIPY_XSLOW=1 to run it") | |
44 mark = _get_mark(item, 'xfail_on_32bit') | |
45 if mark is not None and np.intp(0).itemsize < 8: | |
46 pytest.xfail('Fails on our 32-bit test platform(s): %s' % (mark.args[0],)) | |
47 | |
48 # Older versions of threadpoolctl have an issue that may lead to this | |
49 # warning being emitted, see gh-14441 | |
50 with npt.suppress_warnings() as sup: | |
51 sup.filter(pytest.PytestUnraisableExceptionWarning) | |
52 | |
53 try: | |
54 from threadpoolctl import threadpool_limits | |
55 | |
56 HAS_THREADPOOLCTL = True | |
57 except Exception: # observed in gh-14441: (ImportError, AttributeError) | |
58 # Optional dependency only. All exceptions are caught, for robustness | |
59 HAS_THREADPOOLCTL = False | |
60 | |
61 if HAS_THREADPOOLCTL: | |
62 # Set the number of openmp threads based on the number of workers | |
63 # xdist is using to prevent oversubscription. Simplified version of what | |
64 # sklearn does (it can rely on threadpoolctl and its builtin OpenMP helper | |
65 # functions) | |
66 try: | |
67 xdist_worker_count = int(os.environ['PYTEST_XDIST_WORKER_COUNT']) | |
68 except KeyError: | |
69 # raises when pytest-xdist is not installed | |
70 return | |
71 | |
72 if not os.getenv('OMP_NUM_THREADS'): | |
73 max_openmp_threads = os.cpu_count() // 2 # use nr of physical cores | |
74 threads_per_worker = max(max_openmp_threads // xdist_worker_count, 1) | |
75 try: | |
76 threadpool_limits(threads_per_worker, user_api='blas') | |
77 except Exception: | |
78 # May raise AttributeError for older versions of OpenBLAS. | |
79 # Catch any error for robustness. | |
80 return | |
81 | |
82 | |
83 @pytest.fixture(scope="function", autouse=True) | |
84 def check_fpu_mode(request): | |
85 """ | |
86 Check FPU mode was not changed during the test. | |
87 """ | |
88 old_mode = get_fpu_mode() | |
89 yield | |
90 new_mode = get_fpu_mode() | |
91 | |
92 if old_mode != new_mode: | |
93 warnings.warn("FPU mode changed from {0:#x} to {1:#x} during " | |
94 "the test".format(old_mode, new_mode), | |
95 category=FPUModeChangeWarning, stacklevel=0) |