Namespace packages break's ability to find source code.

Issue #75 invalid
Ned Batchelder repo owner created an issue

Comments (15)

  1. Ned Batchelder reporter

    I tried to reproduce this, with no luck. I installed two of Philip Eby's kits that use namespace packages: ProxyTypes and SymbolType. I ran this code:

    from peak.util.proxies import ObjectProxy
    from peak.util.symbols import Symbol
    p42 = ObjectProxy(42)
    print p42
    AN_EXAMPLE = Symbol('AN_EXAMPLE', __name__)
    print AN_EXAMPLE

    with "coverage run -L", and found the sources just fine.

  2. Buck Evan

    Hi Ned.

    I hope it's not terribly rude to reopen this, but I believe this is still extant, and I have a reliable reproduction for you. Let me know if you want me to instead open a separate issue. This is causing us pain when asserting coverage in our namespaced package.

    Repro: (should be able to copy-paste the whole block)

    git clone
    cd asottile.yaml/
    git checkout coverage-repro
    virtualenv test-repro
    source test-repro/bin/activate
    pip install tox
    tox -e py27

    The test suite "passes" but there's no coverage; it emits the message " warning: No data was collected."

  3. Ned Batchelder reporter

    @buck_golemon Thanks for providing more information, it's fine to re-open the bug. I'll take a look.

  4. Ned Batchelder reporter

    Thanks for the detailed repro instructions! My results were a little different than yours:

    GLOB sdist-make: /Users/ned/foo/bug75/asottile.yaml/
    py27 create: /Users/ned/foo/bug75/asottile.yaml/.tox/py27
    py27 installdeps: -rrequirements_dev.txt
    py27 inst: /Users/ned/foo/bug75/asottile.yaml/.tox/dist/
    py27 runtests: PYTHONHASHSEED='2929019817'
    py27 runtests: commands[0] | coverage erase
    py27 runtests: commands[1] | coverage run -m pytest tests
    ================ test session starts ================
    platform darwin -- Python 2.7.2 -- py-1.4.20 -- pytest-2.5.2
    collected 2 items
    tests/ ..
    ============= 2 passed in 1.58 seconds ==============
    py27 runtests: commands[2] | coverage report --show-missing --fail-under 100
    Name                     Stmts   Miss Branch BrMiss  Cover   Missing
    asottile/__init__            0      0      0      0   100%
    asottile/yaml/__init__      12     12      4      4     0%   1-43
    tests/__init__               0      0      0      0   100%
    tests/yaml_test              8      0      0      0   100%
    TOTAL                       20     12      4      4    33%
    ERROR: InvocationError: '/Users/ned/foo/bug75/asottile.yaml/.tox/py27/bin/coverage report --show-missing --fail-under 100'
    py27 runtests: commands[3] | flake8 asottile tests
    py27 runtests: commands[4] | pylint asottile tests
    __________________ summary __________________
    ERROR:   py27: commands failed

    (BTW: is there a way to get py.test to not use terminal-width punctuation?) This is on OS X, I had the same results on Ubuntu. Are these results also a problem?

  5. Anthony Sottile

    Not sure about the terminal width question but the issue is that I expect asottile/yaml/__init__'s coverage to be nonzero. It is certainly imported in tests/yaml_test so should at least get "coverage" on the import statements and function definitions.

  6. Buck Evan

    If you pipe py.test to cat, it will correctly revert to non-terminal-aware mode:

    $ py.test tests | cat
    ============================= test session starts ==============================
    platform linux2 -- Python 2.7.5 -- py-1.4.20 -- pytest-2.5.2
    collected 2 items
    tests/ ..
    =========================== 2 passed in 0.03 seconds ===========================

    I ran my reproduction steps afresh and still got the same output. I'm on Ubuntu Saucy. I don't have a Mac machine handy at the moment to try out.

    At any rate, you have reproduced the problem to some extent; the correct coverage measure for asottile/yaml/__init__ is 100%.

  7. Ned Batchelder reporter

    Here's what I know: the asottile/yaml/ file is getting installed into the .tox virtualenv, and being run from there. The .coveragerc file has an omit rule that omits all the files installed into the .tox virtualenv. Therefore, no lines in asottile/yaml/ are being covered.

    I don't know if this has to do with namespace packages. It's odd to install your code under test into the .tox virtualenv, for just this reason.

  8. Buck Evan

    Ned: that's actually a core feature of tox. It ensures that the tests run in the same relationship to the code as our users: after installing. It means that if we forget to include a module or package in our, tests won't pass.

    We'll edit our coveragerc and report back. Maybe this was a false alarm :(

  9. Buck Evan

    Is there any way to tell coverage to give me the absolute paths? I suspect the local and installed code are getting mixed up.

  10. Ned Batchelder reporter

    I used the debug feature to see what files were being traced or not, and why: [run] debug=trace

  11. Log in to comment