Commit e19fa590 authored by Stefan Behnel's avatar Stefan Behnel

Allow selecting specific doctests in test modules with "-k pattern", instead...

Allow selecting specific doctests in test modules with "-k pattern", instead of always running all tests.
parent c74381f2
...@@ -617,6 +617,7 @@ class TestBuilder(object): ...@@ -617,6 +617,7 @@ class TestBuilder(object):
self.cleanup_failures = options.cleanup_failures self.cleanup_failures = options.cleanup_failures
self.with_pyregr = with_pyregr self.with_pyregr = with_pyregr
self.cython_only = options.cython_only self.cython_only = options.cython_only
self.doctest_selector = re.compile(options.only_pattern).search if options.only_pattern else None
self.languages = languages self.languages = languages
self.test_bugs = test_bugs self.test_bugs = test_bugs
self.fork = options.fork self.fork = options.fork
...@@ -784,6 +785,7 @@ class TestBuilder(object): ...@@ -784,6 +785,7 @@ class TestBuilder(object):
cleanup_sharedlibs=self.cleanup_sharedlibs, cleanup_sharedlibs=self.cleanup_sharedlibs,
cleanup_failures=self.cleanup_failures, cleanup_failures=self.cleanup_failures,
cython_only=self.cython_only, cython_only=self.cython_only,
doctest_selector=self.doctest_selector,
fork=self.fork, fork=self.fork,
language_level=language_level or self.language_level, language_level=language_level or self.language_level,
warning_errors=warning_errors, warning_errors=warning_errors,
...@@ -824,7 +826,7 @@ def filter_stderr(stderr_bytes): ...@@ -824,7 +826,7 @@ def filter_stderr(stderr_bytes):
class CythonCompileTestCase(unittest.TestCase): class CythonCompileTestCase(unittest.TestCase):
def __init__(self, test_directory, workdir, module, tags, language='c', preparse='id', def __init__(self, test_directory, workdir, module, tags, language='c', preparse='id',
expect_errors=False, expect_warnings=False, annotate=False, cleanup_workdir=True, expect_errors=False, expect_warnings=False, annotate=False, cleanup_workdir=True,
cleanup_sharedlibs=True, cleanup_failures=True, cython_only=False, cleanup_sharedlibs=True, cleanup_failures=True, cython_only=False, doctest_selector=None,
fork=True, language_level=2, warning_errors=False, fork=True, language_level=2, warning_errors=False,
test_determinism=False, test_determinism=False,
common_utility_dir=None, pythran_dir=None, stats=None): common_utility_dir=None, pythran_dir=None, stats=None):
...@@ -842,6 +844,7 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -842,6 +844,7 @@ class CythonCompileTestCase(unittest.TestCase):
self.cleanup_sharedlibs = cleanup_sharedlibs self.cleanup_sharedlibs = cleanup_sharedlibs
self.cleanup_failures = cleanup_failures self.cleanup_failures = cleanup_failures
self.cython_only = cython_only self.cython_only = cython_only
self.doctest_selector = doctest_selector
self.fork = fork self.fork = fork
self.language_level = language_level self.language_level = language_level
self.warning_errors = warning_errors self.warning_errors = warning_errors
...@@ -1314,6 +1317,8 @@ class CythonRunTestCase(CythonCompileTestCase): ...@@ -1314,6 +1317,8 @@ class CythonRunTestCase(CythonCompileTestCase):
else: else:
module = module_or_name module = module_or_name
tests = doctest.DocTestSuite(module) 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())]
with self.stats.time(self.name, self.language, 'run'): with self.stats.time(self.name, self.language, 'run'):
tests.run(result) tests.run(result)
run_forked_test(result, run_test, self.shortDescription(), self.fork) run_forked_test(result, run_test, self.shortDescription(), self.fork)
...@@ -2109,6 +2114,8 @@ def main(): ...@@ -2109,6 +2114,8 @@ def main():
parser.add_option("-T", "--ticket", dest="tickets", parser.add_option("-T", "--ticket", dest="tickets",
action="append", action="append",
help="a bug ticket number to run the respective test in 'tests/*'") help="a bug ticket number to run the respective test in 'tests/*'")
parser.add_option("-k", dest="only_pattern",
help="a regex pattern for selecting doctests and test functions in the test modules")
parser.add_option("-3", dest="language_level", parser.add_option("-3", dest="language_level",
action="store_const", const=3, default=2, action="store_const", const=3, default=2,
help="set language level to Python 3 (useful for running the CPython regression tests)'") help="set language level to Python 3 (useful for running the CPython regression tests)'")
......
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