Skip to content

Report some additional serious errors in junit.xml #8950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
", ".join("[mypy-%s]" % glob for glob in options.per_module_options.keys()
if glob in options.unused_configs)),
file=stderr)
if options.junit_xml:
t1 = time.time()
py_version = '{}_{}'.format(options.python_version[0], options.python_version[1])
util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml,
py_version, options.platform)
maybe_write_junit_xml(time.time() - t0, serious, messages, options)

if MEM_PROFILE:
from mypy.memprofile import print_memory_profile
Expand Down Expand Up @@ -907,10 +903,10 @@ def set_strict_flags() -> None:
for p in special_opts.packages:
if os.sep in p or os.altsep and os.altsep in p:
fail("Package name '{}' cannot have a slash in it.".format(p),
stderr)
stderr, options)
p_targets = cache.find_modules_recursive(p)
if not p_targets:
fail("Can't find package '{}'".format(p), stderr)
fail("Can't find package '{}'".format(p), stderr, options)
targets.extend(p_targets)
for m in special_opts.modules:
targets.append(BuildSource(None, m, None))
Expand All @@ -926,7 +922,7 @@ def set_strict_flags() -> None:
# which causes issues when using the same variable to catch
# exceptions of different types.
except InvalidSourceList as e2:
fail(str(e2), stderr)
fail(str(e2), stderr, options)
return targets, options


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


def fail(msg: str, stderr: TextIO) -> None:
def maybe_write_junit_xml(td: float, serious: bool, messages: List[str], options: Options) -> None:
if options.junit_xml:
py_version = '{}_{}'.format(options.python_version[0], options.python_version[1])
util.write_junit_xml(
td, serious, messages, options.junit_xml, py_version, options.platform)


def fail(msg: str, stderr: TextIO, options: Options) -> None:
"""Fail with a serious error."""
stderr.write('%s\n' % msg)
maybe_write_junit_xml(0.0, serious=True, messages=[msg], options=options)
sys.exit(2)