Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different line number representation (xunit) #779

Open
KD-7 opened this issue Jan 4, 2023 · 3 comments
Open

Different line number representation (xunit) #779

KD-7 opened this issue Jan 4, 2023 · 3 comments
Assignees

Comments

@KD-7
Copy link

KD-7 commented Jan 4, 2023

Hello @mikepenz

When parsing xunit output the tool works except for the line numberings. For the following output no line numbers are found hence it defaults to 1:

<?xml version="1.0" ?>
<testsuite errors="544" failures="0" name="prospector-dodgy-mccabe-profile-validator-pycodestyle-pyflakes-pylint" tests="544" time="33.46">
	<properties/>
	<system-out><![CDATA[]]></system-out>
	<system-err><![CDATA[]]></system-err>
	<testcase name="truelearn_experiments/analyse_results.py-54">
		<error message="String statement has no effect" type="pylint Error"><![CDATA[truelearn_experiments/analyse_results.py:54: [pointless-string-statement(pylint), None] String statement has no effect]]></error>
	</testcase>

Shown as Github annotations:
image

The format of this output is as follows:

  for message in sorted(self.messages):
            testcase_el = xml_doc.createElement("testcase")
            testcase_el.setAttribute("name", f"{self._make_path(message.location.path)}-{message.location.line}")

            failure_el = xml_doc.createElement("error")
            failure_el.setAttribute("message", message.message.strip())
            failure_el.setAttribute("type", "%s Error" % message.source)
            template = "%(path)s:%(line)s: [%(code)s(%(source)s), %(function)s] %(message)s"
            cdata = template % {
                "path": self._make_path(message.location.path),
                "line": message.location.line,
                "source": message.source,
                "code": message.code,
                "function": message.location.function,
                "message": message.message.strip(),
            }

As per the xunit output of prospector: https://github.com/PyCQA/prospector/blob/master/prospector/formatters/xunit.py

@mikepenz
Copy link
Owner

mikepenz commented Jan 4, 2023

Thank you for the report. Looks this project you reference decided yet another format for line numbers.

The action itself supports already the most common variants of line numbers, via either line attributes on the testcase or failure node: https://github.com/mikepenz/action-junit-report/blob/main/src/testParser.ts#L312-L321

Alternative it supports the common format of : as delimiter after the filename: https://github.com/mikepenz/action-junit-report/blob/main/src/testParser.ts#L66-L87

Do you have the chance to adjust the format? The most reliable would be to have line as it's own attribute, as it would not depend on a regex to try to resolve it.

@mikepenz mikepenz self-assigned this Jan 4, 2023
@KD-7
Copy link
Author

KD-7 commented Jan 4, 2023

Hello @mikepenz

When parsing xunit output the tool works except for the line numberings. For the following output no line numbers are found hence it defaults to 1:

<?xml version="1.0" ?>
<testsuite errors="544" failures="0" name="prospector-dodgy-mccabe-profile-validator-pycodestyle-pyflakes-pylint" tests="544" time="33.46">
	<properties/>
	<system-out><![CDATA[]]></system-out>
	<system-err><![CDATA[]]></system-err>
	<testcase name="truelearn_experiments/analyse_results.py-54">
		<error message="String statement has no effect" type="pylint Error"><![CDATA[truelearn_experiments/analyse_results.py:54: [pointless-string-statement(pylint), None] String statement has no effect]]></error>
	</testcase>

Shown as Github annotations: image

The format of this output is as follows:

  for message in sorted(self.messages):
            testcase_el = xml_doc.createElement("testcase")
            testcase_el.setAttribute("name", f"{self._make_path(message.location.path)}-{message.location.line}")

            failure_el = xml_doc.createElement("error")
            failure_el.setAttribute("message", message.message.strip())
            failure_el.setAttribute("type", "%s Error" % message.source)
            template = "%(path)s:%(line)s: [%(code)s(%(source)s), %(function)s] %(message)s"
            cdata = template % {
                "path": self._make_path(message.location.path),
                "line": message.location.line,
                "source": message.source,
                "code": message.code,
                "function": message.location.function,
                "message": message.message.strip(),
            }

As per the xunit output of prospector: https://github.com/PyCQA/prospector/blob/master/prospector/formatters/xunit.py

After reviewing this, I can also see that the file paths arent matched correctly as well

@KD-7
Copy link
Author

KD-7 commented Jan 10, 2023

Thank you for the report. Looks this project you reference decided yet another format for line numbers.

The action itself supports already the most common variants of line numbers, via either line attributes on the testcase or failure node: https://github.com/mikepenz/action-junit-report/blob/main/src/testParser.ts#L312-L321

Alternative it supports the common format of : as delimiter after the filename: https://github.com/mikepenz/action-junit-report/blob/main/src/testParser.ts#L66-L87

Do you have the chance to adjust the format? The most reliable would be to have line as it's own attribute, as it would not depend on a regex to try to resolve it.

Changing the xml file format isnt really an option in this scenario, I was wondering if from the name attribute the - can be used to split the file path and line numberings to give the desired behaviour.
I have also tested a sample XML file where I add the line= attribute, however the file path isnt correctly matched:

<?xml version="1.0" ?>
<testsuite errors="544" failures="0" name="prospector-dodgy-mccabe-profile-validator-pycodestyle-pyflakes-pylint" tests="544" time="33.46">
	<properties/>
	<system-out><![CDATA[]]></system-out>
	<system-err><![CDATA[]]></system-err>
	<testcase name="truelearn_experiments/analyse_results.py" line="54">
		<error message="String statement has no effect" name="pylint Error"><![CDATA[truelearn_experiments/analyse_results.py:54: [pointless-string-statement(pylint), None] String statement has no effect]]></error>
	</testcase>
</testsuite>

CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants