From 61d5e57353bb811df7b5457a1856baee31299429 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Mon, 29 Mar 2021 00:21:20 -0700 Subject: [PATCH] Simplified and optimized test_match_tags(). This simplifies and optimizes runner.py's test_match_tags() because it (1) uses isdisjoint() instead of intersection(), which involves constructing a new set, (2) eliminates a set operation when tags is falsey, (3) eliminates the need for a matched_tags variable, and (4) uses fewer not's, which should make it easier to parse and understand. --- django/test/runner.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/django/test/runner.py b/django/test/runner.py index 6d283bef97..c19e622170 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -858,8 +858,9 @@ def test_match_tags(test, tags, exclude_tags): 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) + if tags and test_tags.isdisjoint(tags): + return False + return test_tags.isdisjoint(exclude_tags) def filter_tests_by_tags(tests, tags, exclude_tags):