mypy --junit-xml: Machine-Readable CI Reports
mypy --junit-xml writes a JUnit XML report alongside its normal output so CI systems can display results.
Many CI platforms render JUnit XML as test results. mypy can emit that format so type failures appear in the same UI as your tests.
What it does
mypy --junit-xml PATH writes a JUnit-style XML file capturing the run result. The file reflects pass/fail, but mypy still uses its normal exit code; the XML is supplementary output, not a replacement for the exit status.
Common usage
mypy --junit-xml mypy-report.xml src/
# keep the human output too and still gate on exit code
mypy --junit-xml reports/mypy.xml --show-error-codes src/; echo "exit=$?"Options
| Flag | What it does |
|---|---|
| --junit-xml <path> | Write a JUnit XML report to the path |
| --show-error-codes | Keep codes in the console output too |
| --no-error-summary | Optional: quiet the console while emitting XML |
| exit code | Still 0/1/2; gate on it, not on the XML |
In CI
Write the XML to a path your CI publishes as a test report, but keep gating the job on mypy exit code, since some integrations show the XML without failing the build. Ensure the parent directory of the --junit-xml path exists first, or mypy cannot write the file.
Common errors in CI
A missing parent directory yields a write error and no report; create reports/ before the run. If the build is green despite type errors, the pipeline is keying off the XML upload step succeeding rather than mypy exit code 1; gate on the exit code. The JUnit XML groups results coarsely, so do not expect one case per error.