Spaces:
Sleeping
Sleeping
File size: 2,775 Bytes
6a86ad5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import sys
sys._running_pytest = True # type: ignore
from sympy.external.importtools import version_tuple
import pytest
from sympy.core.cache import clear_cache, USE_CACHE
from sympy.external.gmpy import GROUND_TYPES
from sympy.utilities.misc import ARCH
import re
try:
import hypothesis
hypothesis.settings.register_profile("sympy_hypothesis_profile", deadline=None)
hypothesis.settings.load_profile("sympy_hypothesis_profile")
except ImportError:
raise ImportError(
"hypothesis is a required dependency to run the SymPy test suite. "
"Install it with 'pip install hypothesis' or 'conda install -c conda-forge hypothesis'"
)
sp = re.compile(r"([0-9]+)/([1-9][0-9]*)")
def process_split(config, items):
split = config.getoption("--split")
if not split:
return
m = sp.match(split)
if not m:
raise ValueError(
"split must be a string of the form a/b " "where a and b are ints."
)
i, t = map(int, m.groups())
start, end = (i - 1) * len(items) // t, i * len(items) // t
if i < t:
# remove elements from end of list first
del items[end:]
del items[:start]
def pytest_report_header(config):
s = "architecture: %s\n" % ARCH
s += "cache: %s\n" % USE_CACHE
version = ""
if GROUND_TYPES == "gmpy":
import gmpy2
version = gmpy2.version()
elif GROUND_TYPES == "flint":
try:
from flint import __version__
except ImportError:
version = "unknown"
else:
version = f'(python-flint=={__version__})'
s += "ground types: %s %s\n" % (GROUND_TYPES, version)
return s
def pytest_terminal_summary(terminalreporter):
if terminalreporter.stats.get("error", None) or terminalreporter.stats.get(
"failed", None
):
terminalreporter.write_sep(" ", "DO *NOT* COMMIT!", red=True, bold=True)
def pytest_addoption(parser):
parser.addoption("--split", action="store", default="", help="split tests")
def pytest_collection_modifyitems(config, items):
"""pytest hook."""
# handle splits
process_split(config, items)
@pytest.fixture(autouse=True, scope="module")
def file_clear_cache():
clear_cache()
@pytest.fixture(autouse=True, scope="module")
def check_disabled(request):
if getattr(request.module, "disabled", False):
pytest.skip("test requirements not met.")
elif getattr(request.module, "ipython", False):
# need to check version and options for ipython tests
if (
version_tuple(pytest.__version__) < version_tuple("2.6.3")
and pytest.config.getvalue("-s") != "no"
):
pytest.skip("run py.test with -s or upgrade to newer version.")
|