{"id":5227,"library":"flake8-formatter-junit-xml","title":"JUnit XML Formatter for flake8","description":"flake8-formatter-junit-xml is a Python package that provides a custom formatter for the flake8 linter, enabling it to output analysis results in the JUnit XML format. This is particularly useful for integrating flake8 reports into Continuous Integration/Continuous Delivery (CI/CD) systems like Jenkins, CircleCI, or GitLab, which typically consume JUnit XML for displaying test and code quality results. The current version is 0.0.6, and its release cadence appears to be infrequent, with the last update in 2018.","status":"maintenance","version":"0.0.6","language":"en","source_language":"en","source_url":"https://github.com/astj/flake8-formatter-junit-xml","tags":["flake8","linter","code quality","junit","xml","ci/cd","formatter"],"install":[{"cmd":"pip install flake8-formatter-junit-xml","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core linter that this package extends.","package":"flake8","optional":false},{"reason":"Dependency for generating the JUnit XML output structure.","package":"junit-xml","optional":false}],"imports":[],"quickstart":{"code":"# First, ensure flake8 is installed (if not already):\n# pip install flake8\n# \n# Then, run flake8 with the custom formatter:\n# flake8 --format junit-xml your_project/ > flake8_report.xml\n\n# Example: Create a dummy Python file with a linting error\nwith open('example.py', 'w') as f:\n    f.write('def foo ( ) : pass\\n')\n\n# Run flake8 with the formatter and direct output to a file\nimport subprocess\nimport os\n\noutput_file = 'flake8_report.xml'\ntry:\n    # Using shell=True for direct execution of the command string\n    # In production, consider passing commands as a list for security\n    subprocess.run(\n        f'flake8 --format junit-xml example.py > {output_file}', \n        shell=True, \n        check=True, \n        capture_output=True\n    )\n    print(f\"JUnit XML report generated at {output_file}\")\n    with open(output_file, 'r') as f:\n        print(f.read())\nexcept subprocess.CalledProcessError as e:\n    print(f\"Flake8 command failed with error: {e.stderr.decode()}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up dummy file and report\n    if os.path.exists('example.py'):\n        os.remove('example.py')\n    if os.path.exists(output_file):\n        os.remove(output_file)","lang":"python","description":"To use the `flake8-formatter-junit-xml` formatter, install the package and then invoke `flake8` from the command line, specifying `--format junit-xml`. The output can then be redirected to an XML file, which CI/CD systems can parse. Note that this formatter is loaded via flake8's entrypoint mechanism, so there's no direct Python import for user-level code."},"warnings":[{"fix":"Thoroughly test compatibility with your specific Python and `flake8` versions. Consider contributing to the project or forking it if specific updates or fixes are needed.","message":"The `flake8-formatter-junit-xml` library has not been updated since April 2018. While it may still function with current `flake8` versions, there is a potential for compatibility issues with newer Python versions or `flake8` releases, and it will not receive updates for new `flake8` features or bug fixes. Users should test thoroughly for their specific environments.","severity":"gotcha","affected_versions":"<=0.0.6"},{"fix":"Configure `flake8` to exclude irrelevant directories by using the `--exclude` command-line option or by defining `exclude` in a `.flake8` configuration file (e.g., `--exclude .git,__pycache__,venv,.tox`).","message":"When using `flake8` with a JUnit XML formatter, ensure that unnecessary directories (e.g., virtual environments, build artifacts, or dependency caches) are excluded from the scan. Failing to do so can lead to significantly inflated JUnit XML report sizes, making them difficult to parse and store, and can slow down CI pipelines.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If a more comprehensive report including successful files is required, you may need to combine this formatter's output with a separate mechanism for listing all scanned files, or consider alternative CI integration strategies.","message":"The formatter outputs only existing issues. If your CI system expects a JUnit XML report that lists *all* processed files, including those with no issues, this formatter might not provide the desired level of detail for 'successful' files. `flake8`'s plugin architecture primarily focuses on reporting violations, not successful checks.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}