@@ -97,11 +97,7 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
97
97
", " .join ("[mypy-%s]" % glob for glob in options .per_module_options .keys ()
98
98
if glob in options .unused_configs )),
99
99
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 )
105
101
106
102
if MEM_PROFILE :
107
103
from mypy .memprofile import print_memory_profile
@@ -907,10 +903,10 @@ def set_strict_flags() -> None:
907
903
for p in special_opts .packages :
908
904
if os .sep in p or os .altsep and os .altsep in p :
909
905
fail ("Package name '{}' cannot have a slash in it." .format (p ),
910
- stderr )
906
+ stderr , options )
911
907
p_targets = cache .find_modules_recursive (p )
912
908
if not p_targets :
913
- fail ("Can't find package '{}'" .format (p ), stderr )
909
+ fail ("Can't find package '{}'" .format (p ), stderr , options )
914
910
targets .extend (p_targets )
915
911
for m in special_opts .modules :
916
912
targets .append (BuildSource (None , m , None ))
@@ -926,7 +922,7 @@ def set_strict_flags() -> None:
926
922
# which causes issues when using the same variable to catch
927
923
# exceptions of different types.
928
924
except InvalidSourceList as e2 :
929
- fail (str (e2 ), stderr )
925
+ fail (str (e2 ), stderr , options )
930
926
return targets , options
931
927
932
928
@@ -987,6 +983,15 @@ def process_cache_map(parser: argparse.ArgumentParser,
987
983
options .cache_map [source ] = (meta_file , data_file )
988
984
989
985
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."""
991
995
stderr .write ('%s\n ' % msg )
996
+ maybe_write_junit_xml (0.0 , serious = True , messages = [msg ], options = options )
992
997
sys .exit (2 )
0 commit comments