How to output coverage XML with nosetests? - python

I'm trying to output the coverage XML of my nosetests so they show up on Hudson. The line I'm executing is:
nosetests --with-gae -v --all-modules --with-xunit --with-coverage
I see the coverage output in the console, but there's no xml file containing the coverage data. How can I get it to output the coverage xml?

Once you've run the nosetests command, there will be a .coverage data file in the directory. If you then run coverage xml, it will create a Cobertura-compatible XML file from the .coverage file.

There is a plugin written for nosetests to do just this.
You just have to add --with-xcoverage once this package is installed. It can be found at:
https://github.com/cmheisel/nose-xcover

Related

can I specify which test files to run in .coveragerc?

My file structure is below,
Logic
--packageA
----file1
----file2
--packageB
----file3
----file4
--tests
----testfile1
----testfile2
----testfile3
--.coveragerc
I'd like to include packageA only for tests, and run testfile1 and testfile2 to measure the coverage.
testfile3 is for packageB.
So I wrote my .coveragerc file,
[run]
branch = True
include = /packageA/*
omit = *tests*
and, when I run coverage with command coverage run --rcfile=../.coveragerc -m pytest in directory tests, it tries running testfile3 as well.
How can I run testfile1 and testfile2 with .coveragerc configuration?
You can use the [run] command_line option to set the command line to use when you run coverage run. But coverage isn't trying to be a general runner. You might want a shell script, a Makefile, or a tox.ini file instead.
Are you typing the coverage run --rcfile=../.coveragerc -m pytest command by hand?

How to create single loggin report from multiple testing files?

I have several test files and I run them one by one using a .bat file.
The batch file looks like this:
py.test --html=Myreport.html -v testfile1.py --tb=short
py.test --html=Myreport.html -v testfile2.py --tb=short
py.test --html=Myreport.html -v testfile3.py --tb=short
The problem is that each test run will overwrite Myreport.html report (so in this case the report will contain only tests present in testfile3.py file as those from the other two files were overwritten).
Is there any way to have all the test results in a single HTML file report?
Thanks

command to generate html report using nosetests over jenkins

nosetests --processes=2 --process-timeout=1800 -v --nocapture -a=attr --attr=api src/tests/externalapi/test_accounts_api.py --with-html
doesn't work
console says:
nosetests: error: no such option: --with-html
Build step 'Execute shell' marked build as failure
You can publish test results by adding post build action named “Publish JUnit test result report” in configure section.
You will need to generate *.xml file with Nose, tell Jenkins what is the name of that file and Jenkins will be able to interpret it and display it in nice looking form.
Option which is interesting for you instead of --with-html is --with-xunit.
Documentation for this option is available here.

Producing xml output with nosetests --processes

I am struggling to get nosetests to output xml.
I have installed nosexml, then in by PYTHONPATH typed ln -s /usr/lib/python2.7/xml/etree/ elementtree.
Now I can type nosetests -plugins and get a list of plugins including xunit.
If I run
nosetests --with-xunit test.py
then I get a file 'nosetests.xml' with test results. So I try to run nose as follows,
nosetests --with-xunit --processes=1 --process-timeout=8000 test.py
and get a file 'nosetests.xml' that says no tests run.
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="0" errors="0" failures="0" skip="0"></testsuite>
Can I use --with-xunit with other options?
Recently solution appeared - xunitmp. Checked - works for me.
It is a bug in the xunit plug-in.
By what I see it was not fixed, so at the moment there is no way to use --processes and --with-xunit options together.

nosetests --cover-html does not generate html docs

I have installed nose for python 2.6 and it works fine but I was trying use the --cover-html option to generate a html report. I typed the following command from the command line:
nosetests --cover-html
It ran the tests but did not generate the html.
Am I missing something ?
It's old news but the order of the options is important:
nosetests --with-coverage --cover-erase --cover-html-dir=C:/temp/res --cover-html test.py
You also need the --with-coverage option to enable the coverage plugin in the first place.

Categories

Resources