diff options
| author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2021-03-05 20:06:33 -0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-08 09:54:01 +0100 |
| commit | 465fdffda0507fa407bf78f5823cd83730b5ffb7 (patch) | |
| tree | 14b0dbdf974641056b907948c54e5eb5705b5517 | |
| parent | 8ff75a3d9ec4290ad7108b2242ac8e6e2aa5d5ea (diff) | |
Refs #32489 -- Simplified filter_tests_by_tags().
| -rw-r--r-- | django/test/runner.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/django/test/runner.py b/django/test/runner.py index aba4fc2b39..46c8c5842d 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -800,18 +800,20 @@ def partition_suite_by_case(suite): ] -def filter_tests_by_tags(suite, tags, exclude_tags): - suite_class = type(suite) - filtered_suite = suite_class() +def test_match_tags(test, tags, exclude_tags): + test_tags = set(getattr(test, 'tags', [])) + test_fn_name = getattr(test, '_testMethodName', str(test)) + if hasattr(test, test_fn_name): + test_fn = getattr(test, test_fn_name) + test_fn_tags = list(getattr(test_fn, 'tags', [])) + test_tags = test_tags.union(test_fn_tags) + matched_tags = test_tags.intersection(tags) + return (matched_tags or not tags) and not test_tags.intersection(exclude_tags) - for test in iter_test_cases(suite): - test_tags = set(getattr(test, 'tags', set())) - test_fn_name = getattr(test, '_testMethodName', str(test)) - test_fn = getattr(test, test_fn_name, test) - test_fn_tags = set(getattr(test_fn, 'tags', set())) - all_tags = test_tags.union(test_fn_tags) - matched_tags = all_tags.intersection(tags) - if (matched_tags or not tags) and not all_tags.intersection(exclude_tags): - filtered_suite.addTest(test) - return filtered_suite +def filter_tests_by_tags(suite, tags, exclude_tags): + suite_class = type(suite) + return suite_class( + test for test in iter_test_cases(suite) + if test_match_tags(test, tags, exclude_tags) + ) |
