question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

junitxml classname="" for additional test paths on command line

See original GitHub issue

We are running pytest with the following invocation:

pytest` ".\first_project\tests" ".\second_project\tests" --junitxml=test_results.xml

To discover and run tests in two folders and compile the results in one test_results.xml folder.

Tests written as single functions in the first folder are listed appropriately in the test_results.xml file with the attributes classname="test_example" file="test_example.py". Results from tests written as simple functions in the second folder have accurate attributes and elements except for the inferred classname attribute, which is inferred as a blank string classname="". The file attribute is also different from the simple filename from the tests discovered in the first folder, but is instead an abreviated full path i.e. file="..\..\first_project\tests\test_example_2.py".

Tests that are methods inside of a class in the first folder are given classname="filename.Classname". In the second path the results are listed as classname=".Classname". So the filename is dropped on the long path here too.

Having test functions return classname=“” for the second path makes some parsing tools choke, like Bamboo’s JUnit Parser.

I’d suggest the test results shouldn’t depend on the order in which the paths were supplied in the command line, perhaps all the tests could have the long version of the file attribute, and that the classname should be inferred from the long attribute appropriately.

pytest version =3.1.3 python version =2.7.12 (Anaconda) Windows 10

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sodrecommented, Aug 2, 2017

I am experiencing the same issue with the classname="" when running tests that are installed as part of a package, i.e. pip install <package-name>.

  • Works fine when calling pytest from the project source directory.
  • Works fine when calling pytest --pyargs <package-name>, after installing it in development mode, i.e. pip install -e .
0reactions
sodrecommented, Aug 2, 2017

I did a little more debugging, and it looks like the issue stems from how the nodeids are assigned. In the first test case we have the nodeids for the tests:

test_package_1.py::test_package_1_function_1
...
::test_package_2_function_1

For the second case the situation is reversed

test_package_2.py::test_package_2_function_1
...
::test_package_1_function_1
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to predict a 'classname' attribute that is visible in ...
I run it using pytest ~/test_pytest/A/AA/a.py --junitxml=b ... junitxml contains <testcase classname="a" file="a.py" line="1" name="test_tt" ...
Read more >
Outputting XML Test Reports — nose2 0.12.0 documentation
You can configure the output filename by setting path in a [junit-xml] section ... Read option from command line and override the value...
Read more >
_pytest.junitxml — pytest documentation
"""Report test results in JUnit-XML format, for use with Jenkins and build integration servers. Based on initial code from Ross Lawley.
Read more >
junitparser – Pythonic JUnit/xUnit Result XML Parser ...
Merge test result xml files. Specify xml parser. For example you can use lxml to speed things up. Invoke from command line, or...
Read more >
Testing in Java & JVM projects - Gradle User Manual
For more details and examples of declaring filters in the build script, please see the TestFilter reference. The command-line option is especially useful...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found