pytest and coverage combination does not work
Try:
py.test --cov-report term --cov=. test.py
The --cov
parameter takes an argument saying which paths to cover. In your example, --cov
would consume test.py
, but then there were no arguments left for py.test about which files to test.
UPDATE: as @hpk42 points out, you need to call your example something other than pytest.py
. When I did this locally, I called it test.py
instead.
user1067671
Updated on June 18, 2022Comments
-
user1067671 almost 2 years
I installed plugin for pytest from here:http://pypi.python.org/pypi/pytest-cov. Then I have a simple test code:
pytest.py:
class TestNumbers: def test_int_float(self): assert 1 == 1.0 def test_int_str(self): assert 1 == 1
I tried to test it with command: 'py.test --cov-report term --cov pytest.py'. But it doesn't work. Even if I gave the entire absolute path of pytest.py it was still no data for collecting. However if I use py.test pytest.py, surely it tested Ok.
I am very confusing about this problem, thanks for help.
-
hpk42 over 11 yearsIf "pytest.py" is the user-module, it will not work. It shadows the the actual py.test (because you do "import pytest" to import helpers/things).
-
John Szakmeister over 11 yearsWhups... that was meant to be
test.py
in my example. You're absolutely right of course.py.test
does at least output a decent error message informing you of this problem though. -
user1067671 over 11 yearsThank you so much. The problem is that used 'pytest.py' as filename. After change it all tests went through Ok. You answer is right. Command should be "py.test --cov-report term --cov=. test.py"
-
floer_m over 8 yearsIf anybody's wondering how to get coverage numbers from doctests (A coworker of mine thought this wasn't supported) --
$ py.test --doctest-modules . --cov-report term --cov=.
or$ py.test --doctest-modules mymodule --cov-report term --cov=mymodule