Skip to content

Add file and line attributes to junit-xml output. #809

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

Merged
merged 1 commit into from
Jul 3, 2015

Conversation

kevincox
Copy link
Contributor

This adds the file and lineno attributes to the junit-xml output
which can be used by tooling to identify where tests come from. This can be
used for many things such as IDEs jumping to failures and test
runners evenly balancing tests among multiple executors.

@kevincox kevincox force-pushed the junitxml-file-attribute branch from 503e2a1 to a7b8cbb Compare June 30, 2015 23:59
@kevincox kevincox changed the title Add file attribute to junit-xml output. Add file and lineno attributes to junit-xml output. Jul 1, 2015
@kevincox kevincox force-pushed the junitxml-file-attribute branch from a7b8cbb to 82806d5 Compare July 1, 2015 00:19
@nicoddemus
Copy link
Member

Hey @kevincox, thanks for the PR.

Some questions:

  1. Are those attributes part of a standard for JUnit xml schema? I did a quick googling and doesn't seem to exist a de-facto standard, but the ones I found (1, 2, 3) did not contain either file or lineno explicit attributes of the testcase tag...
  2. Does the XML file generated by the PR work in Jenkins/other CI servers?
  3. Can you give an example of tools know which make use of those attributes?

Cheers,

@kevincox
Copy link
Contributor Author

kevincox commented Jul 2, 2015

I don't know if there is a "standard". I looked around and couldn't find anything except for a couple of random XML schemas (as you linked).

RSpec JUnit Formatter has file.

CircleCI uses these for [automatic balancing]. They also maintain their own formatter that provides this info for minitest (https://github.com/circleci/minitest-ci/blob/master/lib/minitest/ci.rb)

I haven't tested on Jenkins but since RSpeck JUnit formatter is designed for Jenkins I would imagine it does. And the point of XML is to be extensible. However if someone could give that a test it would be awesome, I don't have any Jenkins available.

@kevincox
Copy link
Contributor Author

kevincox commented Jul 2, 2015

I fixed the tests on windows. I'll rebase it into one commit when I get home.

@nicoddemus
Copy link
Member

@kevincox I did a quick test in a Jenkins instance using your branch, this was the file generated:

<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="0" name="pytest" skips="0" tests="1" time="0.010"><testcase classname="test_foo" file="test_foo.py" lineno="2" name="test_foo" time="0.000999927520752"/></testsuite>

But the jobs unfortunately fails:

[xUnit] [ERROR] - The result file 'W:\workspace\job1\foo-bar.xml' for the metric 'JUnit' is not valid. The result file has been skipped.

So it seems that unfortunately Jenkins has a strict schema checking regarding this... 😞

@kevincox kevincox force-pushed the junitxml-file-attribute branch from 070de8f to 7dfe3af Compare July 2, 2015 22:18
@kevincox
Copy link
Contributor Author

kevincox commented Jul 2, 2015

I have updated the PR to use the line attribute instead because that appears to be Jenkins approved.

@kevincox kevincox changed the title Add file and lineno attributes to junit-xml output. Add file and line attributes to junit-xml output. Jul 2, 2015
@nicoddemus
Copy link
Member

Excellent!

Could you add the url of the junit-10.xsd file in the docstring of the junitxml.py file for future reference?
Also, could you please add yourself to AUTHORS and add an entry into the CHANGELOG?

I will test this myself tomorrow, and if nobody opposes this will merge it then. 😄

This adds the `file` and `line` attributes to the junit-xml output
which can be used by tooling to identify where tests come from. This can be
used for many things such as IDEs jumping to failures and test
runners evenly balancing tests among multiple executors.

Update test_junitxml.py

Foo.
@kevincox kevincox force-pushed the junitxml-file-attribute branch from 7dfe3af to 7fa27af Compare July 2, 2015 22:41
@kevincox
Copy link
Contributor Author

kevincox commented Jul 2, 2015

Updated with the requested changes. Do they look good to you?

@nicoddemus
Copy link
Member

They do, thanks!

@@ -67,6 +67,8 @@

- add a new ``--noconftest`` argument which ignores all ``conftest.py`` files.

- add ``file`` and ``line`` attributes to JUnit-XML output.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, feel free to add a *Thanks to Kevin Cox for PR" like some of the other entries. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha I'm fine with this.

@nicoddemus
Copy link
Member

Just tested and it works perfectly.

Thanks again for the PR! 😄

nicoddemus added a commit that referenced this pull request Jul 3, 2015
Add `file` and `line` attributes to junit-xml output.
@nicoddemus nicoddemus merged commit 9293062 into pytest-dev:master Jul 3, 2015
@kevincox kevincox deleted the junitxml-file-attribute branch July 9, 2015 15:08
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

Successfully merging this pull request may close these issues.

2 participants