conftest.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import sys
  2. sys._running_pytest = True # type: ignore
  3. from sympy.external.importtools import version_tuple
  4. import pytest
  5. from sympy.core.cache import clear_cache, USE_CACHE
  6. from sympy.external.gmpy import GROUND_TYPES, HAS_GMPY
  7. from sympy.utilities.misc import ARCH
  8. import re
  9. sp = re.compile(r'([0-9]+)/([1-9][0-9]*)')
  10. def process_split(config, items):
  11. split = config.getoption("--split")
  12. if not split:
  13. return
  14. m = sp.match(split)
  15. if not m:
  16. raise ValueError("split must be a string of the form a/b "
  17. "where a and b are ints.")
  18. i, t = map(int, m.groups())
  19. start, end = (i-1)*len(items)//t, i*len(items)//t
  20. if i < t:
  21. # remove elements from end of list first
  22. del items[end:]
  23. del items[:start]
  24. def pytest_report_header(config):
  25. s = "architecture: %s\n" % ARCH
  26. s += "cache: %s\n" % USE_CACHE
  27. version = ''
  28. if GROUND_TYPES =='gmpy':
  29. if HAS_GMPY == 1:
  30. import gmpy
  31. elif HAS_GMPY == 2:
  32. import gmpy2 as gmpy
  33. version = gmpy.version()
  34. s += "ground types: %s %s\n" % (GROUND_TYPES, version)
  35. return s
  36. def pytest_terminal_summary(terminalreporter):
  37. if (terminalreporter.stats.get('error', None) or
  38. terminalreporter.stats.get('failed', None)):
  39. terminalreporter.write_sep(
  40. ' ', 'DO *NOT* COMMIT!', red=True, bold=True)
  41. def pytest_addoption(parser):
  42. parser.addoption("--split", action="store", default="",
  43. help="split tests")
  44. def pytest_collection_modifyitems(config, items):
  45. """ pytest hook. """
  46. # handle splits
  47. process_split(config, items)
  48. @pytest.fixture(autouse=True, scope='module')
  49. def file_clear_cache():
  50. clear_cache()
  51. @pytest.fixture(autouse=True, scope='module')
  52. def check_disabled(request):
  53. if getattr(request.module, 'disabled', False):
  54. pytest.skip("test requirements not met.")
  55. elif getattr(request.module, 'ipython', False):
  56. # need to check version and options for ipython tests
  57. if (version_tuple(pytest.__version__) < version_tuple('2.6.3') and
  58. pytest.config.getvalue('-s') != 'no'):
  59. pytest.skip("run py.test with -s or upgrade to newer version.")