Open bensarthou opened 1 month ago
You can make this work by breaking it into two steps: coverage run
with only the .pyc files, but then coverage html
somewhere with the source files. If you have source files on the machine already, then you might need a [paths]
section in your coverage configuration: https://coverage.readthedocs.io/en/7.6.1/config.html#paths
BTW: I'm not sure you need to write your own .py file to run coverage through the API. You should be able to do this with commands on the command line.
Hi @nedbat, thanks for the fast answer
Unfortunately, as the goal is to have the coverage being run automatically in different servers, with different configurations, I need to do this via a script, be it Python or maybe a bash indeed, if the only available option is through the command line I can try going the bash way
But I suppose that any parameter that can be passed through the coverage configuration, could probably be passed through the API, so if you have any idea how to do that, it would really help me
Thanks !
You can try using Coverage.combine()
with a paths
argument to indicate how the source files correspond to the .pyc files.
I've tried this solution, but to no avail unfortunately, it fails with the same error If I understand correctly the Coverage documentation, .combine() is helpful to combine .coverage files from different locations. But here the issue is that the .coverage file is empty, so there is nothing to combine
I've tried different solutions since yesterday, for example loading the tests directly by instance in the TestLoader, instead of using discover, but no results for now
My understanding is that the issue is happening during the "run" phase, where coverage is unable to locate the source file related to the .pyc. I suppose the source
option of the Coverage method is the standard way to go, but using the .pyc seems to hinder this functionnality
Hi,
I'm trying to use coverage to cover tests written in unittest in a production framework, with several constraints, but it fails with this error:
raise NoSource(f"No source for code: '{filename}'.") coverage.exceptions.NoSource: No source for code: 'E:\adele\BSU3PythonCoverage\win_b64\code\python\lib\metrics.py'.
I've looked online and saw this SO post with a similar issue, however the proposed fix does not seems to work here.
I assume the issue is mainly because I run coverage (and the tests) through .pyc, and it breaks the link between source codes at runtime.
Is there a way to make coverage work in this setting ?
You can find below more detailed info
Detailed description of the issue:
My code is structured as such (that cannot be changed unfortunately)
folder_code
contains the code to be tested and coveredfolder_test
contains the source code of the test (using unittest)folder_run
contains the .pyc files of the test and the source code It also contains the file calling coverage through the python API (see below)coverage_main
is written as such:While calling this API through the .pyc file with the following command:
$ python -u -m coverage_main.pyc
I obtain the following log and error:
We can see on the log that tests are correctly ran (the unittest stdout is on top of the log), but coverage fails when doing the report, mostly because the .coverage file is empty (when opening it with an SQL reader, I saw that the database structure is here, but there are no lines)
Feel free to ask for more info if needed