Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,9 @@ def maybe_write_junit_xml(
options: Options,
) -> None:
if options.junit_xml:
if options.bazel:
# Elapsed time would make the output non-reproducible.
td = 0.0
py_version = f"{options.python_version[0]}_{options.python_version[1]}"
if options.junit_format == "global":
util.write_junit_xml(
Expand Down
15 changes: 15 additions & 0 deletions mypy/test/testutil.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from __future__ import annotations

import os
import tempfile
from unittest import TestCase, mock

from mypy.inspections import parse_location
from mypy.main import maybe_write_junit_xml
from mypy.options import Options
from mypy.util import _generate_junit_contents, get_terminal_width


Expand Down Expand Up @@ -109,3 +112,15 @@ def test_serious_error(self) -> None:
platform="test-plat",
)
assert result == expected

def test_junit_time_is_zero_in_bazel_mode(self) -> None:
# Output must be reproducible under Bazel, so elapsed time is not included.
with tempfile.TemporaryDirectory() as tmpdir:
options = Options()
options.bazel = True
options.junit_xml = os.path.join(tmpdir, "junit.xml")
maybe_write_junit_xml(1.23, False, [], {}, options)
with open(options.junit_xml) as f:
result = f.read()
assert 'time="0.000"' in result
assert "1.230" not in result
3 changes: 3 additions & 0 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def fail(message: str) -> NoReturn:
def emit_messages(options: Options, messages: list[str], dt: float, serious: bool = False) -> None:
# ... you know, just in case.
if options.junit_xml:
if options.bazel:
# Elapsed time would make the output non-reproducible.
dt = 0.0
py_version = f"{options.python_version[0]}_{options.python_version[1]}"
write_junit_xml(
dt,
Expand Down
15 changes: 14 additions & 1 deletion mypyc/test/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import tempfile
import unittest

from mypyc.build import get_header_deps, resolve_cfile_deps
from mypy.options import Options
from mypyc.build import emit_messages, get_header_deps, resolve_cfile_deps
from mypyc.ir.ops import BasicBlock
from mypyc.ir.pprint import format_blocks, generate_names_for_ir
from mypyc.irbuild.ll_builder import LowLevelIRBuilder
Expand All @@ -24,6 +25,18 @@ def test_debug_op(self) -> None:
code = format_blocks([block], names, {})
assert code[:-1] == ["L0:", " r0 = 'foo'", " CPyDebug_PrintObject(r0)"]

def test_junit_time_is_zero_in_bazel_mode(self) -> None:
# Output must be reproducible under Bazel, so elapsed time is not included.
with tempfile.TemporaryDirectory() as tmpdir:
options = Options()
options.bazel = True
options.junit_xml = os.path.join(tmpdir, "junit.xml")
emit_messages(options, [], 1.23)
with open(options.junit_xml) as f:
result = f.read()
assert 'time="0.000"' in result
assert "1.230" not in result


class TestHeaderDeps(unittest.TestCase):
"""
Expand Down
Loading