Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/conftest.py
7756 views
"""1Pytest configuration and fixtures for the Numpy test suite.2"""3import os4import tempfile56import hypothesis7import pytest8import numpy910from numpy.core._multiarray_tests import get_fpu_mode111213_old_fpu_mode = None14_collect_results = {}1516# Use a known and persistent tmpdir for hypothesis' caches, which17# can be automatically cleared by the OS or user.18hypothesis.configuration.set_hypothesis_home_dir(19os.path.join(tempfile.gettempdir(), ".hypothesis")20)2122# We register two custom profiles for Numpy - for details see23# https://hypothesis.readthedocs.io/en/latest/settings.html24# The first is designed for our own CI runs; the latter also25# forces determinism and is designed for use via np.test()26hypothesis.settings.register_profile(27name="numpy-profile", deadline=None, print_blob=True,28)29hypothesis.settings.register_profile(30name="np.test() profile",31deadline=None, print_blob=True, database=None, derandomize=True,32suppress_health_check=hypothesis.HealthCheck.all(),33)34# Note that the default profile is chosen based on the presence35# of pytest.ini, but can be overridden by passing the36# --hypothesis-profile=NAME argument to pytest.37_pytest_ini = os.path.join(os.path.dirname(__file__), "..", "pytest.ini")38hypothesis.settings.load_profile(39"numpy-profile" if os.path.isfile(_pytest_ini) else "np.test() profile"40)414243def pytest_configure(config):44config.addinivalue_line("markers",45"valgrind_error: Tests that are known to error under valgrind.")46config.addinivalue_line("markers",47"leaks_references: Tests that are known to leak references.")48config.addinivalue_line("markers",49"slow: Tests that are very slow.")50config.addinivalue_line("markers",51"slow_pypy: Tests that are very slow on pypy.")525354def pytest_addoption(parser):55parser.addoption("--available-memory", action="store", default=None,56help=("Set amount of memory available for running the "57"test suite. This can result to tests requiring "58"especially large amounts of memory to be skipped. "59"Equivalent to setting environment variable "60"NPY_AVAILABLE_MEM. Default: determined"61"automatically."))626364def pytest_sessionstart(session):65available_mem = session.config.getoption('available_memory')66if available_mem is not None:67os.environ['NPY_AVAILABLE_MEM'] = available_mem686970#FIXME when yield tests are gone.71@pytest.hookimpl()72def pytest_itemcollected(item):73"""74Check FPU precision mode was not changed during test collection.7576The clumsy way we do it here is mainly necessary because numpy77still uses yield tests, which can execute code at test collection78time.79"""80global _old_fpu_mode8182mode = get_fpu_mode()8384if _old_fpu_mode is None:85_old_fpu_mode = mode86elif mode != _old_fpu_mode:87_collect_results[item] = (_old_fpu_mode, mode)88_old_fpu_mode = mode899091@pytest.fixture(scope="function", autouse=True)92def check_fpu_mode(request):93"""94Check FPU precision mode was not changed during the test.95"""96old_mode = get_fpu_mode()97yield98new_mode = get_fpu_mode()99100if old_mode != new_mode:101raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"102" during the test".format(old_mode, new_mode))103104collect_result = _collect_results.get(request.node)105if collect_result is not None:106old_mode, new_mode = collect_result107raise AssertionError("FPU precision mode changed from {0:#x} to {1:#x}"108" when collecting the test".format(old_mode,109new_mode))110111112@pytest.fixture(autouse=True)113def add_np(doctest_namespace):114doctest_namespace['np'] = numpy115116@pytest.fixture(autouse=True)117def env_setup(monkeypatch):118monkeypatch.setenv('PYTHONHASHSEED', '0')119120121