[py-dev] What is the recommended way to run test with a coverage report?

meme dough memedough at gmail.com
Sun May 22 06:14:43 CEST 2011


You need an arg to --cov which is the source root you want covered.

py.test -h

  coverage reporting with distributed testing support:
    --cov=path          measure coverage for filesystem path (multi-allowed)

Try something like:

py.test --cov . src\nitroz\test_collections.py

py.test --cov src src\nitroz\test_collections.py

On 20 May 2011 07:53, Baptiste Lepilleur <baptiste.lepilleur at gmail.com> wrote:
> Thanks for the pointer concerning pip, I did not know you could search using
> it.
> Now, I running into a strange missing import error when trying to the test
> with coverage:
> E   ImportError: No module named restdoc
> Any ideas what could be the cause and what this module is?
> Detail below:
> py.test --cov src\nitroz\test_collections.py
> ================================================= test session starts
> =================================================
> platform win32 -- Python 3.2.0 -- pytest-2.0.3
> collected 0 items / 1 errors
> Coverage.py warning: No data was collected.
> ======================================================= ERRORS
> ========================================================
> _________________________________________________ ERROR collecting .
> __________________________________________________
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:312: in
> visit
>>       for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:358: in
> gen
>>               for p in self.gen(subdir):
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:358: in
> gen
>>               for p in self.gen(subdir):
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:358: in
> gen
>>               for p in self.gen(subdir):
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:347: in
> gen
>>       dirs = self.optsort([p for p in entries
> C:\Python32\lib\site-packages\py-1.4.3-py3.2.egg\py\_path\common.py:348: in
> <listcomp>
>>               if p.check(dir=1) and (rec is None or rec(p))])
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\main.py:450: in
> _recurse
>>       ihook.pytest_collect_directory(path=path, parent=self)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\main.py:118: in
> call_matching_hooks
>>       plugins = self.config._getmatchingplugins(self.fspath)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\config.py:283:
> in _getmatchingplugins
>>       plugins += self._conftest.getconftestmodules(fspath)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\config.py:185:
> in getconftestmodules
>>                       clist.append(self.importconftest(conftestpath))
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\config.py:221:
> in importconftest
>>           self._postimport(mod)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\config.py:226:
> in _postimport
>>           self._onimport(mod)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\config.py:272:
> in _onimportconftest
>>       self.pluginmanager.consider_conftest(conftestmodule)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\core.py:181: in
> consider_conftest
>>           self.consider_module(conftestmodule)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\core.py:189: in
> consider_module
>>               self.import_plugin(spec)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\core.py:202: in
> import_plugin
>>               return self.import_plugin(modname[7:])
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\core.py:197: in
> import_plugin
>>           mod = importplugin(modname)
> C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\core.py:323: in
> importplugin
>>       return __import__(importspec, None, None, '__doc__')
> E   ImportError: No module named restdoc
> ----------------------------------- coverage: platform win32, python
> 3.2.0-final-0 ------------------------------------
> Name    Stmts   Miss  Cover
> ---------------------------
> ============================================== 1 error in 18.02 seconds
> ===============================================
>
>
> 2011/5/18 holger krekel <holger at merlinux.eu>
>>
>> Hey Baptiste,
>>
>> On Wed, May 18, 2011 at 17:42 +0200, Baptiste Lepilleur wrote:
>> > The pytest documentation page indicates that it is supported, but
>> > provides
>> > no pointer on how do to this...
>>
>> > Doing a search seem to reveal multiple plug-ins to do that. What is the
>> > recommended one? I'm working on Windows XP / Python 2.6 & 3.2.
>>
>> sorry about that.  The plugin is named pytest-cov, see here
>>
>>    http://pypi.python.org/pypi/pytest-cov
>>
>> If it doesn't work for you i am sure Meme (also here on the list)
>> can answer questions or to issues.
>>
>> > By the way, is there a centralized list of useful plug-ins for pytest ?
>>
>> not really.  However, i recommend to install "pip" and then type:
>>
>>    pip search pytest
>>
>> to get a good list.
>>
>> best,
>> holger
>>
>>
>>
>> >
>> > Baptiste.
>>
>> > _______________________________________________
>> > py-dev mailing list
>> > py-dev at codespeak.net
>> > http://codespeak.net/mailman/listinfo/py-dev
>>
>
>
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
>
>



More information about the Pytest-dev mailing list