Issue #75 open

Namespace packages break coverage.py's ability to find source code.

Ned Batchelder
repo owner created an issue

Comments (14)

  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 proxysymbol.py", and coverage.py found the sources just fine.

  2. buck_golemon

    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 git@github.com:bukzor/asottile.yaml.git
    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 "Coverage.py warning: No data was collected."

  3. 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/setup.py
    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/asottile.yaml-0.1.0.zip
    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/yaml_test.py ..
    
    ============= 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 setup.py
    py27 runtests: commands[4] | pylint asottile tests setup.py
    __________________ 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?

  4. 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.

  5. 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/yaml_test.py ..
    
    =========================== 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%.

  6. Ned Batchelder reporter

    Here's what I know: the asottile/yaml/init.py 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/init.py 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.

  7. 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 setup.py, tests won't pass.

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

  8. Log in to comment