Warning "Already imported a file that will be measured" when using namespace packages · Issue #888 · nedbat/coveragepy (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@remram44

Description

@remram44

Describe the bug

When using namespace packages (declared through setup.py as namespace_packages=[...]) coverage shows warnings "Already imported a file that will be measured" for the __init__.py files.

setup( # ... packages=['testcov'], namespace_packages=['testcov'], )

Those files simply contain the declare_namespace() call:

try: # pragma: no cover import('pkg_resources').declare_namespace(name) except ImportError: # pragma: no cover from pkgutil import extend_path path = extend_path(path, name)

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

  1. What version of Python are you using? 3.6
  2. What version of coverage.py are you using? 5.0
  3. What versions of what packages do you have installed? Only coverage 5.0
  4. What code are you running? Give us a specific commit of a specific repo that we can check out.
    I made a minimal example here: https://github.com/remram44/coverage-bug-888
    Warning shows up in Travis: https://travis-ci.org/remram44/coverage-bug-888/builds/625849023#L460
  5. What commands did you run? coverage run --source=/tmp/testcov/app,/tmp/testcov/plugin app/testcov/main.py (see run.sh in repo)

Expected behavior

I didn't expect to see a warning.

Additional context
This problem was uncovered in ReproZip: https://travis-ci.org/VIDA-NYU/reprozip/jobs/625416082#L4117

Documentation on namespace packages with pkg_resources: https://packaging.python.org/guides/packaging-namespace-packages/#pkg-resources-style-namespace-packages