Pregunta

I'm trying to use coverage.py to find the coverage of functional tests executed against a server process, deployed using .pyc files. And it seems coverage does not support this.

Trying to overcome the problem, I created a simple .py module that calls other pyc files for which I provided the sources into a separate folder:

coverage run --source=../src main.py

The message I get back is

Coverage.py warning: No data was collected.

Any pointers?

¿Fue útil?

Solución

Indeed, coverage 3.6 does not currently support running with pyc files. See https://bitbucket.org/ned/coveragepy/issue/264/coverage-wont-run-pyc-files.

The trick is to create a simple 'driver' source file that uses the pyc files, like main.py in the question body. At report time, you need to pair the source and the executed pyc files.

Here how to do this (my compiled files are stored in the current folder (pyc) and source files in ../src):

[root@host pyc]# cat .coveragerc
[run]
parallel = true

[paths]
mysources =
    ../src
    /root/lucian/coverage/module1/pyc

[root@host pyc]# coverage run main.py
[root@host pyc]# coverage combine
[root@host pyc]# coverage report
Name                                                     Stmts   Miss  Cover
----------------------------------------------------------------------------
/root/lucian/coverage/module1/src/main                       1      0   100%
/root/lucian/coverage/module1/src/test_coverage_callee       3      0   100%
/root/lucian/coverage/module1/src/test_coverage_caller       3      0   100%
----------------------------------------------------------------------------
TOTAL                                                        7      0   100%

Note that the 3rd line under [paths] must be a full path (another coverage defect).

Thanks to Ned who helped me through this on the coverage mailing list.

Otros consejos

Currently, coverage.py must have access to the .py (source) files to do reporting. Ned tells me there is a ticket in to make this possible in the future.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top