mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-37957: Allow regrtest to receive a file with test (and subtests) to ignore (GH-16989)
When building Python in some uncommon platforms there are some known tests that will fail. Right now, the test suite has the ability to ignore entire tests using the -x option and to receive a filter file using the --matchfile filter. The problem with the --matchfile option is that it receives a file with patterns to accept and when you want to ignore a couple of tests and subtests, is too cumbersome to lists ALL tests that are not the ones that you want to accept and he problem with -x is that is not easy to ignore just a subtests that fail and the whole test needs to be ignored. For these reasons, add a new option to allow to ignore a list of test and subtests for these situations.
This commit is contained in:
parent
ef5aa9af7c
commit
e0cd8aa70a
7 changed files with 169 additions and 24 deletions
|
@ -155,6 +155,24 @@ class ParseArgsTestCase(unittest.TestCase):
|
|||
self.assertTrue(ns.single)
|
||||
self.checkError([opt, '-f', 'foo'], "don't go together")
|
||||
|
||||
def test_ignore(self):
|
||||
for opt in '-i', '--ignore':
|
||||
with self.subTest(opt=opt):
|
||||
ns = libregrtest._parse_args([opt, 'pattern'])
|
||||
self.assertEqual(ns.ignore_tests, ['pattern'])
|
||||
self.checkError([opt], 'expected one argument')
|
||||
|
||||
self.addCleanup(support.unlink, support.TESTFN)
|
||||
with open(support.TESTFN, "w") as fp:
|
||||
print('matchfile1', file=fp)
|
||||
print('matchfile2', file=fp)
|
||||
|
||||
filename = os.path.abspath(support.TESTFN)
|
||||
ns = libregrtest._parse_args(['-m', 'match',
|
||||
'--ignorefile', filename])
|
||||
self.assertEqual(ns.ignore_tests,
|
||||
['matchfile1', 'matchfile2'])
|
||||
|
||||
def test_match(self):
|
||||
for opt in '-m', '--match':
|
||||
with self.subTest(opt=opt):
|
||||
|
@ -961,6 +979,42 @@ class ArgsTestCase(BaseTestCase):
|
|||
regex = re.compile("^(test[^ ]+).*ok$", flags=re.MULTILINE)
|
||||
return [match.group(1) for match in regex.finditer(output)]
|
||||
|
||||
def test_ignorefile(self):
|
||||
code = textwrap.dedent("""
|
||||
import unittest
|
||||
|
||||
class Tests(unittest.TestCase):
|
||||
def test_method1(self):
|
||||
pass
|
||||
def test_method2(self):
|
||||
pass
|
||||
def test_method3(self):
|
||||
pass
|
||||
def test_method4(self):
|
||||
pass
|
||||
""")
|
||||
all_methods = ['test_method1', 'test_method2',
|
||||
'test_method3', 'test_method4']
|
||||
testname = self.create_test(code=code)
|
||||
|
||||
# only run a subset
|
||||
filename = support.TESTFN
|
||||
self.addCleanup(support.unlink, filename)
|
||||
|
||||
subset = [
|
||||
# only ignore the method name
|
||||
'test_method1',
|
||||
# ignore the full identifier
|
||||
'%s.Tests.test_method3' % testname]
|
||||
with open(filename, "w") as fp:
|
||||
for name in subset:
|
||||
print(name, file=fp)
|
||||
|
||||
output = self.run_tests("-v", "--ignorefile", filename, testname)
|
||||
methods = self.parse_methods(output)
|
||||
subset = ['test_method2', 'test_method4']
|
||||
self.assertEqual(methods, subset)
|
||||
|
||||
def test_matchfile(self):
|
||||
code = textwrap.dedent("""
|
||||
import unittest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue