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_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)


@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 (pytest.__version__ < '2.6.3' and
            pytest.config.getvalue('-s') != 'no'):
            pytest.skip("run py.test with -s or upgrade to newer version.")

@@ -136,16 +136,540 @@
 r_cache%0A
+import re%0A%0Asp = re.compile(r'(%5B0-9%5D+)/(%5B1-9%5D%5B0-9%5D*)')%0A%0Adef process_split(session, config, items):%0A    split = config.getoption(%22--split%22)%0A    if not split:%0A        return%0A    m = sp.match(split)%0A    if not m:%0A        raise ValueError(%22split must be a string of the form a/b %22%0A                         %22where a and b are ints.%22)%0A    i, t = map(int, m.groups())%0A    start, end = (i-1)*len(items)//t, i*len(items)//t%0A%0A    if i %3C t:%0A        # remove elements from end of list first%0A        del items%5Bend:%5D%0A    del items%5B:start%5D%0A
 %0A%0Adef py
@@ -1441,16 +1441,284 @@
 True)%0A%0A%0A
+def pytest_addoption(parser):%0A    parser.addoption(%22--split%22, action=%22store%22, default=%22%22,%0A        help=%22split tests%22)%0A%0A%0Adef pytest_collection_modifyitems(session, config, items):%0A    %22%22%22 pytest hook. %22%22%22%0A    # handle splits%0A    process_split(session, config, items)%0A%0A%0A
 @pytest.

Add --split option to pytest