summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-11-19 23:46:49 (GMT)
committerGitHub <noreply@github.com>2019-11-19 23:46:49 (GMT)
commite0cd8aa70a3ce19c3d3712568940aa0cbd9aa97b (patch)
tree6399ae3384460b71742378f52878cd11464f9e17 /Lib/test/support
parentef5aa9af7c7e493402ac62009e4400aed7c3d54e (diff)
downloadcpython-e0cd8aa70a3ce19c3d3712568940aa0cbd9aa97b.zip
cpython-e0cd8aa70a3ce19c3d3712568940aa0cbd9aa97b.tar.gz
cpython-e0cd8aa70a3ce19c3d3712568940aa0cbd9aa97b.tar.bz2
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.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py50
1 files changed, 38 insertions, 12 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 5ad32b8..7e1b30c 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2096,7 +2096,9 @@ def _run_suite(suite):
# By default, don't filter tests
_match_test_func = None
-_match_test_patterns = None
+
+_accept_test_patterns = None
+_ignore_test_patterns = None
def match_test(test):
@@ -2112,18 +2114,45 @@ def _is_full_match_test(pattern):
# as a full test identifier.
# Example: 'test.test_os.FileTests.test_access'.
#
- # Reject patterns which contain fnmatch patterns: '*', '?', '[...]'
- # or '[!...]'. For example, reject 'test_access*'.
+ # ignore patterns which contain fnmatch patterns: '*', '?', '[...]'
+ # or '[!...]'. For example, ignore 'test_access*'.
return ('.' in pattern) and (not re.search(r'[?*\[\]]', pattern))
-def set_match_tests(patterns):
- global _match_test_func, _match_test_patterns
+def set_match_tests(accept_patterns=None, ignore_patterns=None):
+ global _match_test_func, _accept_test_patterns, _ignore_test_patterns
- if patterns == _match_test_patterns:
- # No change: no need to recompile patterns.
- return
+ if accept_patterns is None:
+ accept_patterns = ()
+ if ignore_patterns is None:
+ ignore_patterns = ()
+
+ accept_func = ignore_func = None
+
+ if accept_patterns != _accept_test_patterns:
+ accept_patterns, accept_func = _compile_match_function(accept_patterns)
+ if ignore_patterns != _ignore_test_patterns:
+ ignore_patterns, ignore_func = _compile_match_function(ignore_patterns)
+
+ # Create a copy since patterns can be mutable and so modified later
+ _accept_test_patterns = tuple(accept_patterns)
+ _ignore_test_patterns = tuple(ignore_patterns)
+
+ if accept_func is not None or ignore_func is not None:
+ def match_function(test_id):
+ accept = True
+ ignore = False
+ if accept_func:
+ accept = accept_func(test_id)
+ if ignore_func:
+ ignore = ignore_func(test_id)
+ return accept and not ignore
+
+ _match_test_func = match_function
+
+
+def _compile_match_function(patterns):
if not patterns:
func = None
# set_match_tests(None) behaves as set_match_tests(())
@@ -2151,10 +2180,7 @@ def set_match_tests(patterns):
func = match_test_regex
- # Create a copy since patterns can be mutable and so modified later
- _match_test_patterns = tuple(patterns)
- _match_test_func = func
-
+ return patterns, func
def run_unittest(*classes):