Skip to content

Add --soft-fail option to capture Mypy output without blocking CI #18859

@balihb

Description

@balihb

Feature

Add a --soft-fail option to Mypy that allows capturing its output without causing a hard failure in CI/CD pipelines.

Pitch

Currently, Mypy exits with a 1 status code when type errors are found, which is expected behavior. However, in many CI/CD pipelines (especially those integrating with SonarQube or similar tools), it's useful to capture all Mypy output while still allowing the pipeline to continue in a controlled way.

A --soft-fail option would:

  • Allow Mypy to run normally and produce full output, including errors and warnings.
  • Exit with status code 0 so that CI/CD jobs don’t automatically fail.
  • Still allow external tools like SonarQube to analyze and report issues without interfering with the pipeline’s flow.

I currently have a one liner workaround in tox:

https://gist.github.com/balihb/0b64435c0e8f553791071cea4a897c91

[tox] min_version = 4.20 envlist = # renovate: datasource=docker depName=python 3.13 [testenv] skip_install = true pass_env = FORCE_COLOR MYPY_* NO_COLOR PIP_* PYTHONUNBUFFERED PY_COLORS TERM deps = -r requirements.txt -r requirements-mypy.txt commands = commands = python -c "import os, re, shlex, subprocess, sys; \  from pathlib import Path; \  result = subprocess.run(['mypy'] + shlex.split('{posargs:src}'), check=False, text=True, capture_output=True); \  result.stdout.strip() and sys.stdout.write(result.stdout); \  result.stderr.strip() and sys.stderr.write(result.stderr); \  output = Path(os.getenv('MYPY_TOX_OUTPUT', default='.report/mypy/output.txt')); \  output.parent.mkdir(parents=True, exist_ok=True); \  output.write_text(re.compile(r'\x1b\\[[0-9;]*?m').sub('', result.stdout)); \  sys.exit(1 if result.returncode == 2 else 0)"

but this is far from ideal.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions