Cover.py in .pyc files.

I am trying to use cover.py to find coverage of functional tests run against a server process deployed using .pyc files. And the coverage doesn't seem to support this.

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

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

The message I receive is

 Coverage.py warning: No data was collected. 

Any pointers?

+6
source share
2 answers

Indeed, coverage 3.6 currently does not support working 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 pyc files, for example main.py in the body of the question. During the report, you need to combine the source and executable pyc files.

Here's how to do it (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 third line in [paths] must be the full path (another coverage defect).

Thanks to Ned, who helped me get through this mailing list.

+1
source

Currently to access .py (source) files for coverage. Ned tells me there is a ticket to make this possible in the future.

0
source

Source: https://habr.com/ru/post/954004/


All Articles