Add built-in JUnit XML reporter#10985
Conversation
for more information, see https://pre-commit.ci
|
Hi @Pierre-Sassoulas hope you doing good , |
|
Hey @hamza-mobeen, thank you for working on this. It seems another tests was not independant, do you mind fixing it ? (You can check tests locally with pytest, as you're a first time contributor I must approve all the pipeline). |
This comment has been minimized.
This comment has been minimized.
alright sure |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10985 +/- ##
=======================================
Coverage 96.19% 96.20%
=======================================
Files 178 179 +1
Lines 19683 19720 +37
=======================================
+ Hits 18934 18971 +37
Misses 749 749
🚀 New features to boost your workflow:
|
|
hello @Pierre-Sassoulas I made a recent update this fixes the ci errors we were having please check it out when you have a moment. thanks |
|
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit ff43fad |
|
Hello @Pierre-Sassoulas still waiting for your feedback. thanks |
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Hello @hamza-mobeen thank you for your work on this.
You should add junit in the format list of doc/user_guide/usage/output.rst, and junit to the --output-format help string in pylint/lint/base_options.py and regenerate the documezntation with tox -e docs.
Also, there's existing junit solution https://pypi.org/project/pylint-junit/ (730k download a month), or https://github.com/aroden-crowdstrike/pylint2junit (5k download a month), for example. Did you consider those ? Guaranteeing retro-compatibility with the big one would be nice.
| for msg in module_messages: | ||
| failure_msg = ( | ||
| f"{msg.msg_id}({msg.symbol}): {msg.msg or ''} " f"(line {msg.line})" | ||
| ) | ||
| failure_el = ET.SubElement( | ||
| testcase_el, | ||
| "failure", | ||
| type=msg.category, | ||
| message=failure_msg, | ||
| ) | ||
| failure_el.text = ( | ||
| f"{msg.abspath}:{msg.line}: [{msg.msg_id}({msg.symbol})] " | ||
| f"{msg.msg or ''}" | ||
| ) | ||
| total_failures += 1 |
There was a problem hiding this comment.
The fact that a message is a failure or not should depend on pylint options like fail-on, or error-only (some message can be raised without pylint exiting in error). Is there only one level of message in the junit spec ? Because error message or fatal message are very different thing in pylint.
There was a problem hiding this comment.
@Pierre-Sassoulas I've resolved this with my current commit please check it out when you available
…cs and help string
|
@Pierre-Sassoulas thanks for the feedback, I just made an updated regarding your feedback, please check it out when you free, thanks |
Fixes #9143
Type of Changes
Description
Closes #9143
Problem
Third-party JUnit reporter packages (
pylint2junit,pylint-junit) have not been working reliably since pylint 2.15 due to internal API changes. Users who need JUnit XML output for their CI/CD pipelines (e.g. Azure DevOps) are left without a working solution.Solution
This PR adds a built-in
JUnitReporterclass so users can run:and get valid JUnit-compatible XML output directly from pylint, with no external dependencies required.
What was changed
4 files changed, 434 insertions(+)
pylint/reporters/junit_reporter.py(new file)New
JUnitReporterclass extendingBaseReporter, following the same pattern used byJSONReporter. Key details:<testcase>, and each violation becomes a<failure>child element.xml.etree.ElementTreefrom the standard library — zero new dependencies.<failure>element'stypeattribute maps directly to the pylint message category (error,warning,convention,refactor, etc.).<failure>element'smessageattribute follows the format:{msg_id}({symbol}): {message} (line {line}).<failure>element's text body includes the full absolute file path for CI tool linking.display_reportsand_displayare no-ops, same asJSONReporter.register()function is provided for auto-discovery byutils.register_plugins().pylint/reporters/__init__.py(modified)Added
JUnitReporterimport and__all__export:Closes #9143
Checklist
skip-newsif the change does not need to be in the changelog.towncrier create <IssueNumber>.<type>which will beincluded in the changelog.
<type>can be one of the types defined in./towncrier.toml.If necessary you can write details or offer examples on how the new change is supposed to work.
tox -e docsDon't hesitate to open multiple PRs if the change requires it. If your review is so
big it requires to actually plan and allocate time to review, it's more likely
that it's going to go stale.
and preferred name in
script/.contributors_aliases.json