-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modules imported with importlib don't record coverage #1002
Comments
I'm trying the repo you've made (thanks!) and I can see that the plugin is reported as 0%. But I cannot reproduce what you say:
When I comment out the
I'm using |
The I thought there was an issue already asking for a way to indicate that |
Here is the issue about the directory/package confusion: #268. Though here, it's a package because you don't have an "app" directory (my mistake). |
I wasn't clear enough, sorry. You'd also have to comment the [run]
branch = True
#source =
# app
#[paths]
#source =
# src
# .tox/*/site-packages
[report]
show_missing = True
With "module name" are you referring to the key used for |
What is actually printed here? I don't see the covered modules in the output either - but might be because they are traced correctly ? |
Adding The name |
BTW, I just pushed some changes on the master branch to add more information in the |
Is this still an issue for you? |
Running on Python 3.10 with coverage 6.1.2 it still is an issue. The initially references repo still works. If I find some time I'll check out the new |
The
Coverage.py implements your If you change this line in core.py, it works:
Is that a reasonable change to your code? Or, if there's another package that plugins live in, it could be included in the |
@nedbat's comment helped me solve this exact issue on my very own codebase! The |
@MLNW thanks for the confirmation, that is good to hear. Others: feel free to re-open with more details if this is still a problem for you. |
Describe the bug
When a module is dynamically imported with
importlib
it won't record any coverage data.To Reproduce
I've created a minimal example illustrating the problem here: https://github.com/timofurrer/coverage-importlib-test
The repository consists of a single Python package with a single module
src/app/core.py
which usesthe
importlib
code from here to dynamically importsrc/app/plugins/plugin_mod.py
.When running the tests with
tox
the output shows the following:So no coverage for
plugin_mod.py
...Expected behavior
... However, I'd expect it to have 100% coverage as the others do.
Importing the module statically using
import app.plugins.plugin_mod.py
insrc/app/core.py
instead of withimportlib
works like a charm.Additional information
The following
.coveragerc
configuration is used:Edit:
The problem seems to be related to the
[run] source
config - removing it, correctly reports coverage for the plugin module,but it also includes modules not from the
app
packages into the coverage report - which is undesired.Adding the
app.plugins
package to[run] source
doesn't help.The config also seems like a common one - e.g. attrs uses it, too
The text was updated successfully, but these errors were encountered: