Skip to content

Commit 3adb2e9

Browse files
authored
Report some additional serious errors in junit.xml (#8950)
Previously junit.xml was not generated for invalid package name errors, among other things.
1 parent 348a9d4 commit 3adb2e9

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

mypy/main.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
9797
", ".join("[mypy-%s]" % glob for glob in options.per_module_options.keys()
9898
if glob in options.unused_configs)),
9999
file=stderr)
100-
if options.junit_xml:
101-
t1 = time.time()
102-
py_version = '{}_{}'.format(options.python_version[0], options.python_version[1])
103-
util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml,
104-
py_version, options.platform)
100+
maybe_write_junit_xml(time.time() - t0, serious, messages, options)
105101

106102
if MEM_PROFILE:
107103
from mypy.memprofile import print_memory_profile
@@ -907,10 +903,10 @@ def set_strict_flags() -> None:
907903
for p in special_opts.packages:
908904
if os.sep in p or os.altsep and os.altsep in p:
909905
fail("Package name '{}' cannot have a slash in it.".format(p),
910-
stderr)
906+
stderr, options)
911907
p_targets = cache.find_modules_recursive(p)
912908
if not p_targets:
913-
fail("Can't find package '{}'".format(p), stderr)
909+
fail("Can't find package '{}'".format(p), stderr, options)
914910
targets.extend(p_targets)
915911
for m in special_opts.modules:
916912
targets.append(BuildSource(None, m, None))
@@ -926,7 +922,7 @@ def set_strict_flags() -> None:
926922
# which causes issues when using the same variable to catch
927923
# exceptions of different types.
928924
except InvalidSourceList as e2:
929-
fail(str(e2), stderr)
925+
fail(str(e2), stderr, options)
930926
return targets, options
931927

932928

@@ -987,6 +983,15 @@ def process_cache_map(parser: argparse.ArgumentParser,
987983
options.cache_map[source] = (meta_file, data_file)
988984

989985

990-
def fail(msg: str, stderr: TextIO) -> None:
986+
def maybe_write_junit_xml(td: float, serious: bool, messages: List[str], options: Options) -> None:
987+
if options.junit_xml:
988+
py_version = '{}_{}'.format(options.python_version[0], options.python_version[1])
989+
util.write_junit_xml(
990+
td, serious, messages, options.junit_xml, py_version, options.platform)
991+
992+
993+
def fail(msg: str, stderr: TextIO, options: Options) -> None:
994+
"""Fail with a serious error."""
991995
stderr.write('%s\n' % msg)
996+
maybe_write_junit_xml(0.0, serious=True, messages=[msg], options=options)
992997
sys.exit(2)

0 commit comments

Comments
 (0)