How to get code coverage for files which are raising (module-not-measured) error

I am generating code coverage for my project. Where it is not showing code coverage for some Python files, those are triggered by a helper module that is using subprocess.run internally to call those Python files.

I tried including sigterm = True in .coveragerc file but that didn’t worked.

To handle this scenario I tried the coverage API Approach, like the below one.

import coverage

cov = coverage.Coverage()
cov.start()

# Below is a method that will execute a bunch of code that needs to be covered. 
earth = Planet()
earth.rotate()

cov.stop()
cov.save()

cov.html_report()

But when I run the file, it shows me the below error and coverage is not generating

CoverageWarning: Module Space was previously imported, but not measured (module-not-measured)
self.warn(msg, slug="module-not-measured")

Space is my module name where all the code exists.

I found some details on this in documentation but no info provided on how to bypass this to get the coverage.

@nedbat Can you please help me with it?

Thanks in Advance.

Since you mentioned subprocess, make sure you have enabled coverage measurement for those processes: Measuring sub-processes — Coverage.py 7.4.3 documentation

2 Likes

I solved the issue by following the documentation, Thanks a lot @nedbat