Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest and coverage combination does not work

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.

like image 353
user1067671 Avatar asked Nov 29 '12 08:11

user1067671


1 Answers

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.

like image 139
John Szakmeister Avatar answered Oct 22 '22 21:10

John Szakmeister