Skip to content
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

"Already imported a file that will be measured" reported for coverage itself #905

Open
asottile opened this issue Dec 21, 2019 · 9 comments
Open
Labels
bug

Comments

@asottile
Copy link
Contributor

@asottile asottile commented Dec 21, 2019

Describe the bug
Admittedly, my configuration is probably ~slightly wrong -- but since this is a new message in coverage 5.x I figured I'd point it out. The warning seems non-actionable for this particular case.

To Reproduce
How can we reproduce the problem? Please be specific.

This .coveragerc (distilled from a larger example)

[run]
source = .

coverage installed into ./venv

$ ./venv/bin/pip freeze
coverage==5.0

any old simple python file, here's t.py

print('hello world')

run coverage run -m t

$ coverage run -m t
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/bin/coverage (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/__init__.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/version.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/control.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/env.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/annotate.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/files.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/backward.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/misc.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/report.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/collector.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/debug.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/disposition.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/pytracer.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/tracer.cpython-36m-x86_64-linux-gnu.so (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/config.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/tomlconfig.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/context.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/data.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/sqldata.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/numbits.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/html.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/results.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/templite.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/inorout.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/python.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/parser.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/bytecode.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/phystokens.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/plugin.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/jsonreport.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/plugin_support.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/summary.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/xmlreport.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/multiproc.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/cmdline.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: /tmp/x/venv/lib/python3.6/site-packages/coverage/execfile.py (already-imported)
hello world

Expected behavior

the warnings are pretty noisy, and in my case not really actionable (this is a development env, I'll later run from tox where omit will exclude these particular files).

I realize I probably should add omit = venv*/* or something of the sort

Additional context

nothing really, just new noise :)

thanks again for coverage, I don't know what I'd do without it

@asottile asottile added the bug label Dec 21, 2019
@nedbat
Copy link
Owner

@nedbat nedbat commented Dec 21, 2019

Perhaps this is a variant of #876, that coverage should be smarter about ignoring local venv directories.

@nedbat
Copy link
Owner

@nedbat nedbat commented Dec 21, 2019

Wait, somehow i missed that this was about coverage itself...!

@asottile
Copy link
Contributor Author

@asottile asottile commented Dec 22, 2019

yep! and bin/coverage (sys.modules['__main__']) and site.py (which I assume is due to virtualenv shenanigans and doesn't get covered by the stdlib filter?)

@nedbat nedbat modified the milestones: 5.0.1, 5.0.2 Dec 22, 2019
@nedbat
Copy link
Owner

@nedbat nedbat commented Jan 4, 2020

This is similar to #876: when using --source=., the venv is part of that source tree, so all of venv is considered measurable.

You can fix it by adding this to .coveragerc:

[run]
omit = venv/*

BTW, I don't think this is a slightly wrong configuration, I think it's really common, unless I missed something?

@nedbat nedbat modified the milestones: 5.0.2, 5.0.3, 5.0.4 Jan 6, 2020
@nedbat nedbat removed this from the 5.0.4 milestone Mar 17, 2020
@caleb15
Copy link

@caleb15 caleb15 commented Mar 26, 2020

--omit=venv/* worked for me, thanks nedbat.

@erdseb
Copy link

@erdseb erdseb commented Aug 21, 2020

omit = venv/* stops working once plugins come into play. Let me provide proof:

Start with the exact same same setup as described above:

cd "$(mktemp -d)"
python3 -m venv venv
source venv/bin/activate
pip install coverage
echo $'[run]\nsource = .\nomit = venv/*' > .coveragerc  # the dollar syntax is a Bashism, saves "echo -e"
echo "print('hello world')" > t.py

Verify that there are no "already-imported" warnings yet:

$ coverage run -m t
hello world

Add plugin django_coverage_plugin to the mix:

pip install django django_coverage_plugin
echo 'plugins = django_coverage_plugin' >> .coveragerc

See "already-imported" warnings from the omitted path appear:

$ coverage run -m t
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/context.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/exceptions.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/base.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/library.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/engine.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/utils.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/__init__.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/defaultfilters.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/smartif.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/template/defaulttags.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/templatetags/__init__.py (already-imported)
Coverage.py warning: Already imported a file that will be measured: [..]/venv/lib/python3.8/site-packages/django/templatetags/i18n.py (already-imported)
hello world

Is that a bug in coverage or in django_coverage_plugin?
Is it considered the same thing or should I open a new bug?

@asottile
Copy link
Contributor Author

@asottile asottile commented Aug 21, 2020

@erdseb this issue is about coverage itself, not django

@piranna
Copy link

@piranna piranna commented Sep 11, 2020

Any update on this?

@tlrh314
Copy link

@tlrh314 tlrh314 commented Nov 19, 2020

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.