This commit is contained in:
Kovid Goyal 2020-01-18 08:15:20 +05:30
commit aaacfd1447
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 5 deletions

View File

@ -57,12 +57,12 @@ class TestImports(unittest.TestCase):
self.assertGreater(self.base_check(base, exclude_packages, exclude_modules), 1000)
def find_tests(which_tests=None):
def find_tests(which_tests=None, exclude_tests=None):
ans = []
a = ans.append
def ok(x):
return not which_tests or x in which_tests
return (not which_tests or x in which_tests) and (not exclude_tests or x not in exclude_tests)
if ok('build'):
from calibre.test_build import find_tests
@ -154,17 +154,24 @@ class Test(Command):
description = 'Run the calibre test suite'
def add_options(self, parser):
parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)')
parser.add_option('--test-module', '--test-group', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)),
help='The test module to run (can be specified more than once for multiple modules). Choices: %s' % ', '.join(sorted(TEST_MODULES)))
parser.add_option('--test-verbosity', type=int, default=4, help='Test verbosity (0-4)')
parser.add_option('--test-name', default=[], action='append',
help='The name of an individual test to run. Can be specified more than once for multiple tests. The name of the'
' test is the name of the test function without the leading test_. For example, the function test_something()'
' can be run by specifying the name "something".')
parser.add_option('--exclude-test-module', default=[], action='append', type='choice', choices=sorted(map(str, TEST_MODULES)),
help='A test module to be excluded from the test run (can be specified more than once for multiple modules).'
' Choices: %s' % ', '.join(sorted(TEST_MODULES)))
parser.add_option('--exclude-test-name', default=[], action='append',
help='The name of an individual test to be excluded from the test run. Can be specified more than once for multiple tests.')
def run(self, opts):
from calibre.utils.run_tests import run_cli, filter_tests_by_name
tests = find_tests(which_tests=frozenset(opts.test_module))
from calibre.utils.run_tests import run_cli, filter_tests_by_name, remove_tests_by_name
tests = find_tests(which_tests=frozenset(opts.test_module), exclude_tests=frozenset(opts.exclude_test_module))
if opts.test_name:
tests = filter_tests_by_name(tests, *opts.test_name)
if opts.exclude_test_name:
tests = remove_tests_by_name(tests, *opts.exclude_test_name)
run_cli(tests, verbosity=opts.test_verbosity)

View File

@ -113,6 +113,14 @@ def filter_tests_by_name(suite, *names):
return filter_tests(suite, q)
def remove_tests_by_name(suite, *names):
names = {x if x.startswith('test_') else 'test_' + x for x in names}
def q(test):
return test._testMethodName not in names
return filter_tests(suite, q)
def filter_tests_by_module(suite, *names):
names = frozenset(names)