Skip to content

Toggle JUnit behavior with INI option #4511

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 10 commits into from
Jan 24, 2019

Conversation

jhunkeler
Copy link
Contributor

Continuation of #4493
cc: @nicoddemus @RonnyPfannschmidt

Known issues so far:

  1. A few failing tests
  2. Debugging output needs to be removed
  3. There's no good way to inform either _NodeReporter or LogXML about which family they should choose. Not without horrifically breaking either of them.
  4. Use of module-global variable

Note:
Despite the tests failing this does emit different/corrected XML for the selected junit_family=[(old|xunit1),xunit2].

@jhunkeler
Copy link
Contributor Author

Also, I left #4493 intact in case this PR is considered "too crazy".

@RonnyPfannschmidt
Copy link
Member

at first glance interesting approach - unfortunately i might not be able to review it in a timely manner this week

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

after doing a first deeper review i really like the approach,
it keeps things as they are reasonably simple

the reduction of the detail level of the testcases doesn't sit too well with me, but i would prefer if someone with a deep need for correct and detailed junitxml sorted that out

for kl, vl in left.items():
for kr, vr in right.items():
if not isinstance(vl, list):
raise NotImplementedError(type(vl))
Copy link
Member

Choose a reason for hiding this comment

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

should be a TypeError

# This includes custom attributes, because they are not valid here.
# TODO: Convert invalid attributes to properties to preserve "something"
temp_attrs = {}
for key in self.attrs.keys():
Copy link
Member

Choose a reason for hiding this comment

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

this should jsut use items() to avoid double lookup

merge_family(families["xunit1"], families["_base_old"])

# Alias "old" to xUnit 1.x
families["old"] = families["xunit1"]
Copy link
Member

Choose a reason for hiding this comment

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

instead of old i propose the name legacy

tests=numtests,
time="%.3f" % suite_time_delta,
).unicode(indent=0)
)
logfile.close()

# TODO: GET RID OF
Copy link
Member

Choose a reason for hiding this comment

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

TODO

@@ -0,0 +1 @@
``--junitxml`` emits XML data compatible with JUnit's offical schema releases.
Copy link
Member

Choose a reason for hiding this comment

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

Please add a link to the official document

@codecov
Copy link

codecov bot commented Jan 14, 2019

Codecov Report

Merging #4511 into features will decrease coverage by 3.75%.
The diff coverage is 95.23%.

Impacted file tree graph

@@             Coverage Diff             @@
##           features   #4511      +/-   ##
===========================================
- Coverage     95.76%     92%   -3.76%     
===========================================
  Files           111     111              
  Lines         24683   24636      -47     
  Branches       2446    2445       -1     
===========================================
- Hits          23637   22666     -971     
- Misses          739    1566     +827     
- Partials        307     404      +97
Flag Coverage Δ
#docs 29.54% <23.8%> (+0.05%) ⬆️
#doctesting 29.54% <23.8%> (+0.05%) ⬆️
#linting 29.54% <23.8%> (+0.05%) ⬆️
#linux 92% <95.23%> (-3.59%) ⬇️
#nobyte ?
#numpy ?
#pexpect ?
#py27 ?
#py34 ?
#py35 ?
#py36 ?
#py37 91.91% <95.23%> (-2.02%) ⬇️
#trial ?
#windows ?
#xdist 91.91% <95.23%> (-1.9%) ⬇️
Impacted Files Coverage Δ
testing/test_junitxml.py 97.8% <100%> (-0.16%) ⬇️
src/_pytest/junitxml.py 93.92% <92.1%> (-0.48%) ⬇️
src/_pytest/_code/_py2traceback.py 20% <0%> (-71.12%) ⬇️
testing/test_pdb.py 48.9% <0%> (-50.13%) ⬇️
src/_pytest/compat.py 75.75% <0%> (-21.22%) ⬇️
src/_pytest/unittest.py 73.71% <0%> (-20.58%) ⬇️
testing/python/approx.py 80.45% <0%> (-19.18%) ⬇️
src/_pytest/debugging.py 62.83% <0%> (-18.92%) ⬇️
src/_pytest/recwarn.py 83.6% <0%> (-14.76%) ⬇️
src/_pytest/python_api.py 83.26% <0%> (-14.23%) ⬇️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5dcb370...2a09992. Read the comment docs.

* Remove non-standard testcase elements: 'file' and 'line'
* Replace testcase element 'skips' with 'skipped'
* Time resolution uses the standard format: 0.000
* Tests use corrected XML output with proper attributes
* "legacy" is no longer a copy of "xunit1"
* Attempts to use "legacy" will redirect to "xunit1"
* record_xml_attribute is not compatible outside of legacy family
* Replace call to method/override raw() with to_xml()
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @jhunkeler!

@nicoddemus
Copy link
Member

Can we remove the WIP status from the title or is there still work to be done in this PR?

@jhunkeler
Copy link
Contributor Author

Thanks :)

I do have one concern though. This PR tries to retain backwards compatibility but it did fall short in one place. Originally this code used skips to denote a skipped test, however now it has been renamed to skipped (to satisfy the xunit2 requirement).

That's to say with xunit1 enabled, and with the way the XML classes were written, you'll end up with skipped in the XML output rather than skips. Was skips ever a hard requirement for an older (ancient) version of JUnit? Or part of an official schema that no longer exists? I wasn't able to track down any documentation anywhere... If skips needs to be retained for perfect 1:1 compatibility I fear the if/else branches required to make that work (or any hacky solution) will make the code unreadable.

I'm not sure if this is a showstopper so I'd like to get an opinion on the matter.

@RonnyPfannschmidt
Copy link
Member

a nicely self-contained if/else with a todo comment and followup issue is a good starting point - eventually we ought to investigate if it can be done nicely with inheritance or another mechanism

@nicoddemus
Copy link
Member

I agree, if we move the logic to a free function I think the code still will be ok

@nicoddemus nicoddemus added this to the 4.2 milestone Jan 23, 2019
@nicoddemus
Copy link
Member

I wasn't able to track down any documentation anywhere...

After looking around at some xUnit schemas, indeed skips does not appear to be part of any of the xUnit "standards". I've been using Jenkins for years now and never seen it displaying a "skipped" test before, so I suspect our current xUnit format is faulty anyway.

I propose we merge this as is and deal with any problems later in a bug-fix release, if they ever happen.

@nicoddemus nicoddemus changed the title WIP: Toggle JUnit behavior with INI option Toggle JUnit behavior with INI option Jan 24, 2019
@nicoddemus nicoddemus merged commit 9905a73 into pytest-dev:features Jan 24, 2019
@ianling
Copy link

ianling commented Mar 8, 2019

Due to the XML file containing the word "skipped" instead of "skips", as of pytest version 4.2.0, the JUnit plugin in Jenkins fails to parse the XML file if you are using the post-build step "Publish JUnit reports generated with handlebars". I don't make use of the webpage that build step generates, so I just removed the step from my builds.

In case anyone happens to come across this error and spend several hours troubleshooting it, there's the solution. Downgrade Pytest or get rid of that build step in Jenkins.

@nicoddemus
Copy link
Member

Hi @ianling,

Did you try to set the junit_family=legacy ini option?

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.

4 participants