Commit fa922c9d authored by Stefan Behnel's avatar Stefan Behnel

Test runner: make "-k" option also select amongst the unit tests, not only doctests.

(Tried the "pattern" argument to loadTestsFromModule() in the unittest module, but it's not always taken into account, so manual selection is what works.)
parent 2769b3c9
......@@ -640,7 +640,7 @@ class TestBuilder(object):
self.cleanup_failures = options.cleanup_failures
self.with_pyregr = with_pyregr
self.cython_only = options.cython_only
self.doctest_selector = re.compile(options.only_pattern).search if options.only_pattern else None
self.test_selector = re.compile(options.only_pattern).search if options.only_pattern else None
self.languages = languages
self.test_bugs = test_bugs
self.fork = options.fork
......@@ -813,7 +813,7 @@ class TestBuilder(object):
cleanup_sharedlibs=self.cleanup_sharedlibs,
cleanup_failures=self.cleanup_failures,
cython_only=self.cython_only,
doctest_selector=self.doctest_selector,
test_selector=self.test_selector,
fork=self.fork,
language_level=language_level or self.language_level,
warning_errors=warning_errors,
......@@ -851,10 +851,21 @@ def filter_stderr(stderr_bytes):
return stderr_bytes
def filter_test_suite(test_suite, selector):
filtered_tests = []
for test in test_suite._tests:
if isinstance(test, unittest.TestSuite):
filter_test_suite(test, selector)
elif not selector(test.id()):
continue
filtered_tests.append(test)
test_suite._tests[:] = filtered_tests
class CythonCompileTestCase(unittest.TestCase):
def __init__(self, test_directory, workdir, module, tags, language='c', preparse='id',
expect_errors=False, expect_warnings=False, annotate=False, cleanup_workdir=True,
cleanup_sharedlibs=True, cleanup_failures=True, cython_only=False, doctest_selector=None,
cleanup_sharedlibs=True, cleanup_failures=True, cython_only=False, test_selector=None,
fork=True, language_level=2, warning_errors=False,
test_determinism=False,
common_utility_dir=None, pythran_dir=None, stats=None):
......@@ -872,7 +883,7 @@ class CythonCompileTestCase(unittest.TestCase):
self.cleanup_sharedlibs = cleanup_sharedlibs
self.cleanup_failures = cleanup_failures
self.cython_only = cython_only
self.doctest_selector = doctest_selector
self.test_selector = test_selector
self.fork = fork
self.language_level = language_level
self.warning_errors = warning_errors
......@@ -1344,8 +1355,8 @@ class CythonRunTestCase(CythonCompileTestCase):
else:
module = module_or_name
tests = doctest.DocTestSuite(module)
if self.doctest_selector is not None:
tests._tests[:] = [test for test in tests._tests if self.doctest_selector(test.id())]
if self.test_selector:
filter_test_suite(tests, self.test_selector)
with self.stats.time(self.name, self.language, 'run'):
tests.run(result)
run_forked_test(result, run_test, self.shortDescription(), self.fork)
......@@ -1542,6 +1553,8 @@ class CythonUnitTestCase(CythonRunTestCase):
with self.stats.time(self.name, self.language, 'import'):
module = import_ext(self.module, ext_so_path)
tests = unittest.defaultTestLoader.loadTestsFromModule(module)
if self.test_selector:
filter_test_suite(tests, self.test_selector)
with self.stats.time(self.name, self.language, 'run'):
tests.run(result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment