from __future__ import print_function, division

import sys
sys._running_pytest = True

import pytest
from sympy.core.cache import clear_cache


def pytest_report_header(config):
    from sympy.utilities.misc import ARCH
    s = "architecture: %s\n" % ARCH
    from sympy.core.cache import USE_CACHE
    s += "cache:        %s\n" % USE_CACHE
    from sympy.core.compatibility import GROUND_TYPES, HAS_GMPY
    version = ''
    if GROUND_TYPES =='gmpy':
        if HAS_GMPY == 1:
            import gmpy
        elif HAS_GMPY == 2:
            import gmpy2 as gmpy
        version = gmpy.version()
    s += "ground types: %s %s\n" % (GROUND_TYPES, version)
    return s


def pytest_addoption(parser):
    parser.addoption("--slow", action="store_true",
        help="allow slow tests to run")


def pytest_configure(config):
    # register an additional marker
    config.addinivalue_line("markers", "slow: slow test")


def pytest_runtest_setup(item):
    if not isinstance(item, pytest.Function):
        return
    if item.config.getoption("--slow"):
        if not 'slow' in item.keywords:
            pytest.skip()
    elif 'slow' in item.keywords:
        pytest.skip("slow test: pass --slow to run")


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_runtest_teardown():
    clear_cache()

@@ -679,532 +679,89 @@
 est_
-addoption(parser):%0A    parser.addoption(%22--slow%22, action=%22store_true%22,%0A        help=%22allow slow tests to run%22)%0A%0A%0Adef pytest_configure(config):%0A    # register an additional marker%0A    config.addinivalue_line(%22markers%22, %22slow: slow test%22)%0A%0A%0Adef pytest_runtest_setup(item):%0A    if not isinstance(item, pytest.Function):%0A        return%0A    if item.config.getoption(%22--slow%22):%0A        if not 'slow' in item.keywords:%0A            pytest.skip()%0A    elif 'slow' in item.keywords:%0A        pytest.skip(%22slow test: pass --slow to run%22)
+runtest_setup(item):%0A    if not isinstance(item, pytest.Function):%0A        return
 %0A%0A%0Ad

remove --slow option from py.test as it is not the appropriate way to use py.test