Producing xml output with nosetests --processes - python

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.

Related

How to use pytest-custom_exit_code plugin

Need help!
I have a job on Gitlab ci, that runs tests and reruns failed ones. If there are no failed tests, job fails with exit code 5, that means that there are no tests for running. I found out that there is plugin "pytest-custom_exit_code", but I don't know how to correctly use it.
I need just to add command 'pytest --suppress-no-test-exit-code' to my runner.sh?
It looks like this now:
#!/bin/sh
/usr/local/bin/pytest -m test
/usr/local/bin/pytest -m --last-failed --last-failed-no-failures none test
Assumption here is that plugin is installed first using
pip install pytest-custom_exit_code
command like option pytest --suppress-no-test-exit-code should work after that.
If configuration file like .pytest.ini is used , following lines should be added in it
[pytest]
addopts = --suppress-no-test-exit-code

How to test single file under pytest

How do you test a single file in pytest? I could only find ignore options and no "test this file only" option in the docs.
Preferably this would work on the command line instead of setup.cfg, as I would like to run different file tests in the ide. The entire suite takes too long.
simply run pytest with the path to the file
something like
pytest tests/test_file.py
Use the :: syntax to run a specific test in the test file:
pytest test_mod.py::test_func
Here test_func can be a test method or a class (e.g.: pytest test_mod.py::TestClass).
For more ways and details, see "Specifying which tests to run" in the docs.
This is pretty simple:
$ pytest -v /path/to/test_file.py
The -v flag is to increase verbosity. If you want to run a specific test within that file:
$ pytest -v /path/to/test_file.py::test_name
If you want to run test which names follow a patter you can use:
$ pytest -v -k "pattern_one or pattern_two" /path/to/test_file.py
You also have the option of marking tests, so you can use the -m flag to run a subset of marked tests.
test_file.py
def test_number_one():
"""Docstring"""
assert 1 == 1
#pytest.mark.run_these_please
def test_number_two():
"""Docstring"""
assert [1] == [1]
To run test marked with run_these_please:
$ pytest -v -m run_these_please /path/to/test_file.py
This worked for me:
python -m pytest -k some_test_file.py
This works for individual test functions too:
python -m pytest -k test_about_something

nose get list of test without running them

Is there a way to get a list of all the tests currently recognized by nose, without running them?
According to the doc
--collect-only Enable collect-only: Collect and output test names only, don't run any tests. [COLLECT_ONLY]
However when I do nosetests --collect-only I get:
Ran 101 tests in 0.642s
OK
How can I get names those tests?
Try with the -v option:
nosetests -v --collect-only
If you're trying to debug how nose actually finds your tests, go for -vv

How to output coverage XML with nosetests?

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

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