Flake8 JUnit Report Basic
flake8-junit-report-basic is a simple Python command-line tool (version 3.0.0) that converts the output from Flake8 static analysis into the JUnit XML format. This conversion facilitates integration with Continuous Integration (CI) systems like Jenkins or CircleCI, allowing them to display Flake8 failures alongside other test results. The project shows recent activity with its 3.0.0 release, though its historical context includes an older, unmaintained fork.
Warnings
- breaking Version 3.0.0 introduces a significant change by generating individual testcases for each Flake8 error, rather than one testcase per file. This new output structure for the JUnit XML may break existing CI pipelines or tools that rely on the previous XML format.
- gotcha The command-line executable provided by the `flake8-junit-report-basic` package is named `flake8_junit`, not `flake8-junit-report-basic`. Users should invoke `flake8_junit` directly after installation.
- gotcha There are older, unmaintained forks (e.g., `initios/flake8-junit-report`) with similar names whose GitHub READMEs display 'WARNING: Not mantained'. Ensure you are referring to the active `ricardogarfe/flake8-junit-report` repository and installing `flake8-junit-report-basic` for the latest version and active development.
Install
-
pip install flake8-junit-report-basic
Quickstart
# 1. Create a dummy Python file with a Flake8 error
Path('my_module.py').write_text('import os; x = 1 ') # E222, W292
# 2. Run Flake8 and save its output to a file
# This simulates the output that flake8_junit expects
result = subprocess.run(
['flake8', '--output-file', 'flake8_report.txt', 'my_module.py'],
capture_output=True, text=True
)
# 3. Convert the Flake8 output file to JUnit XML format
# The executable is named 'flake8_junit'
junit_result = subprocess.run(
['flake8_junit', 'flake8_report.txt', 'junit_report.xml'],
capture_output=True, text=True
)
# Optional: Print the generated JUnit XML content
print(Path('junit_report.xml').read_text())