Skip to content

Commit 68a82e9

Browse files
JukkaLilevkivskyi
authored andcommitted
Add _cached suffix to test cases in fine-grained tests with cache (#4558)
This makes it obvious when a test case fails whether the test case uses caching or not. Previously both kinds of failures looked similar, which was confusing. There is one non-obvious bit: the _cached suffix must be inserted before other suffixes such as -skip since those suffixes are tested using endswith(), and it's probably better to have such "effectful" suffixes at the end so that they are prominent.
1 parent e0eb047 commit 68a82e9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mypy/test/data.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,23 @@ def collect(self) -> Iterator[pytest.Item]: # type: ignore
598598
optional_out=suite.optional_out,
599599
native_sep=suite.native_sep):
600600
if suite.filter(case):
601+
case.name = add_test_name_suffix(case.name, suite.test_name_suffix)
601602
yield MypyDataCase(case.name, self, case)
602603

603604

605+
def add_test_name_suffix(name: str, suffix: str) -> str:
606+
# Find magic suffix of form "-foobar" (used for things like "-skip").
607+
m = re.search(r'-[-A-Za-z0-9]+$', name)
608+
if m:
609+
# Insert suite-specific test name suffix before the magic suffix
610+
# which must be the last thing in the test case name since we
611+
# are using endswith() checks.
612+
magic_suffix = m.group(0)
613+
return name[:-len(magic_suffix)] + suffix + magic_suffix
614+
else:
615+
return name + suffix
616+
617+
604618
def is_incremental(testcase: DataDrivenTestCase) -> bool:
605619
return 'incremental' in testcase.name.lower() or 'incremental' in testcase.file
606620

@@ -661,6 +675,9 @@ class DataSuite:
661675
base_path = '.'
662676
optional_out = False
663677
native_sep = False
678+
# Name suffix automatically added to each test case in the suite (can be
679+
# used to distinguish test cases in suites that share data files)
680+
test_name_suffix = ''
664681

665682
# Assigned from MypyDataCase.runtest
666683
update_data = False

mypy/test/testfinegrainedcache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010

1111
class FineGrainedCacheSuite(mypy.test.testfinegrained.FineGrainedSuite):
1212
use_cache = True
13+
test_name_suffix = '_cached'

0 commit comments

Comments
 (0)