Skip to content

Commit bb0017d

Browse files
mthuurnemsullivan
authored andcommitted
Disable cache when producing reports (#6076)
If the cache is used, coverage information will only be reported for modules that were not in the cache. To allow testing, support multiple steps in command line tests. Fixes #5103
1 parent d61babb commit bb0017d

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

mypy/build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,10 @@ def __init__(self, data_dir: str,
504504
self.stale_modules = set() # type: Set[str]
505505
self.rechecked_modules = set() # type: Set[str]
506506
self.flush_errors = flush_errors
507-
self.cache_enabled = options.incremental and (
508-
not options.fine_grained_incremental or options.use_fine_grained_cache)
507+
self.cache_enabled = (options.incremental
508+
and (not options.fine_grained_incremental
509+
or options.use_fine_grained_cache)
510+
and not reports.reporters)
509511
self.fscache = fscache
510512
self.find_module_cache = FindModuleCache(self.search_paths, self.fscache, self.options)
511513
if options.sqlite_cache:

mypy/test/testcmdline.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ class PythonCmdlineSuite(DataSuite):
3232
native_sep = True
3333

3434
def run_case(self, testcase: DataDrivenTestCase) -> None:
35-
test_python_cmdline(testcase)
35+
for step in [1] + sorted(testcase.output2):
36+
test_python_cmdline(testcase, step)
3637

3738

38-
def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
39+
def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
3940
assert testcase.old_cwd is not None, "test was not properly set up"
4041
# Write the program to a file.
4142
program = '_program.py'
@@ -75,12 +76,14 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
7576
# Ignore stdout, but we insist on empty stderr and zero status.
7677
if err or result:
7778
raise AssertionError(
78-
'Expected zero status and empty stderr, got %d and\n%s' %
79-
(result, '\n'.join(err + out)))
79+
'Expected zero status and empty stderr%s, got %d and\n%s' %
80+
(' on step %d' % step if testcase.output2 else '',
81+
result, '\n'.join(err + out)))
8082
for path, expected_content in testcase.output_files:
8183
if not os.path.exists(path):
8284
raise AssertionError(
83-
'Expected file {} was not produced by test case'.format(path))
85+
'Expected file {} was not produced by test case{}'.format(
86+
path, ' on step %d' % step if testcase.output2 else ''))
8487
with open(path, 'r', encoding='utf8') as output_file:
8588
actual_output_content = output_file.read().splitlines()
8689
normalized_output = normalize_file_output(actual_output_content,
@@ -93,17 +96,19 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
9396
for line in normalized_output]
9497
normalized_output = normalize_error_messages(normalized_output)
9598
assert_string_arrays_equal(expected_content.splitlines(), normalized_output,
96-
'Output file {} did not match its expected output'.format(
97-
path))
99+
'Output file {} did not match its expected output{}'.format(
100+
path, ' on step %d' % step if testcase.output2 else ''))
98101
else:
99102
if testcase.normalize_output:
100103
out = normalize_error_messages(err + out)
101104
obvious_result = 1 if out else 0
102105
if obvious_result != result:
103106
out.append('== Return code: {}'.format(result))
104-
assert_string_arrays_equal(testcase.output, out,
105-
'Invalid output ({}, line {})'.format(
106-
testcase.file, testcase.line))
107+
expected_out = testcase.output if step == 1 else testcase.output2[step]
108+
assert_string_arrays_equal(expected_out, out,
109+
'Invalid output ({}, line {}){}'.format(
110+
testcase.file, testcase.line,
111+
' on step %d' % step if testcase.output2 else ''))
107112

108113

109114
def parse_args(line: str) -> List[str]:

test-data/unit/reports.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,15 @@ class Foo:
357357
@attr.s
358358
class Z(object):
359359
pass
360+
361+
[case testCoverageIgnoresCache]
362+
-- Performs two runs to verify that cached information does not prevent
363+
-- modules from being included in reports.
364+
# cmd: mypy --linecount-report report a.py
365+
[file a.py]
366+
empty = False
367+
[out]
368+
[out2]
369+
[outfile report/linecount.txt]
370+
1 1 0 0 total
371+
1 1 0 0 a

0 commit comments

Comments
 (0)