Issue #98 new

No source for code

Alex Gaynor
created an issue

When running coverage html I'm getting a no source for code error, pointing at a file that doesn't exist, and never did exist. No idea what the cause is:

{{{ (shelfworthy)alex@alex-laptop:~/projects/eldarion/shelfworthy/shelfworthy$ coverage run ./ test events [snip] ................

Ran 16 tests in 0.264s

OK Destroying test database 'default'... (shelfworthy)alex@alex-laptop:~/projects/eldarion/shelfworthy/shelfworthy$ coverage html --omit=/home/alex/.virtualenvs/ No source for code: '/home/alex/projects/eldarion/shelfworthy/shelfworthy/' (shelfworthy)alex@alex-laptop:~/projects/eldarion/shelfworthy/shelfworthy$ ls ls: cannot access No such file or directory (shelfworthy)alex@alex-laptop:~/projects/eldarion/shelfworthy/shelfworthy$ coverage --version, version 3.4.


Comments (15)

  1. Ned Batchelder repo owner

    Alex, this is indeed mysterious! Can you post (or email me) a tarball with a reproducible case? Barring that, can you show the output of "coverage debug sys" and "coverage debug data" ?

  2. Ned Batchelder repo owner

    Simplest things first: are you sure there's no models.pyc there?

    Do you have any files in your tree that aren't represented in the debug data output? Maybe it is being mis-attributed to the shelfworthy directory.

    As another clue, we can list the actual 24 lines measured in that phantom file:

    $ python
    >>> import coverage
    >>> cov = coverage.coverage()

    This will print a list of line numbers.

  3. Anonymous

    The identified line numbers are:

    [1, 2, 4, 6, 9, 10, 23, 26, 29, 30, 32, 33, 34, 36, 38, 40, 41, 43, 49, 56, 59, 62, 68, 75]

    Looking at the result of the data debug and comparing to the find -name "" the only one unaccounted for (in my local dir, ignoring the venv) is totally empty. No pycs lingering in this dir.

  4. Alex Gaynor reporter

    Sigh, above anonymous was me.

    As another datapoint (possibly unrelated but I have no idea), when running the django-taggit ( tests, in the exact same fashion and generating html in the same way (same omit of the virtualenv) the resulting HTML still includes all my stuff in the virtualenv. Possibly a wholly unrelated thing, but I don't know.

  5. Ram Rachum

    I'm experiencing this bug also. For me it's in my open-source project and not a client project, so I can try to make a reproducible case. Will that help?

  6. Ram Rachum

    Here's the tarball for my project:

    (This happens for me under Ubuntu 10.10, Python 2.6, nose 0.11.1, coverage 3.4.)

    How to reproduce:

    Add the equivalents of the following 3 directories to your PYTHONPATH:

    export PYTHONPATH="/home/coolrr/Desktop/GarlicSim/garlicsim:/home/coolrr/Desktop/GarlicSim/garlicsim_lib:/home/coolrr/Desktop/GarlicSim/garlicsim_wx:"

    Go to GarlicSim/tests/.

    Run nose:

    nosetests --exclude=unittest2 --with-coverage --cover-package=garlicsim,garlicsim_lib,garlicsim_wx

    Run coverage:

    coverage html

    You get:

    No source for code: '/home/coolrr/Desktop/GarlicSim/garlicsim/'

  7. Ned Batchelder repo owner

    Hmmm, I'm not seeing the same results. I get 4 test failures, because I have to install numpy and wx. In the meantime, I get this from "coverage debug data | grep shared". What do you get?

    ned.karmic ~/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/tests> coverage debug data | grep shared
    /home/ned/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/garlicsim/general_misc/address_tools/ 12 lines
    /home/ned/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/tests/test_asynchronous_crunching/ 3 lines
    /home/ned/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/tests/test_general_misc/test_cute_profile/ 5 lines
    /home/ned/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/tests/test_general_misc/test_sleek_refs/ 15 lines
  8. Ned Batchelder repo owner

    After installing numpy (wxpython doesn't play well with virtualenv), the errors changed, and now I get:

    ERROR: Failure: ImportError (No module named shared)
    Traceback (most recent call last):
      File "/home/ned/coverage/bug98/vpy/lib/python2.6/site-packages/nose/", line 382, in loadTestsFromName
        addr.filename, addr.module)
      File "/home/ned/coverage/bug98/vpy/lib/python2.6/site-packages/nose/", line 39, in importFromPath
        return self.importFromDir(dir_path, fqname)
      File "/home/ned/coverage/bug98/vpy/lib/python2.6/site-packages/nose/", line 86, in importFromDir
        mod = load_module(part_fqname, fh, filename, desc)
      File "/home/ned/coverage/bug98/cool-RR-GarlicSim-af5978a/garlicsim/tests/test_asynchronous_crunching/", line 29, in <module>
        from .shared import MustachedThreadCruncher
    ImportError: No module named shared

    I don't understand how this worked for you: there is no in the tests/ directory, which I think is where it would have to be for this relative import to work. Perhaps there's a clue here, since my tests fail trying to find, and your "coverage html" fails trying to find

  9. Ram Rachum

    I tried now and I got the same error as you, missing `` file. I don't know how this worked before.

    I'm currently working on a big release for the project, and I've been changing my code really rapidly. Mainly I'm writing a lot of tests, reorganizing them (for example I renamed the main `tests` folder to `test_garlicsim`), and checking coverage. Once in a few coverage runs I get this annoying bug, and now I got it again, for a different "file":

    No source for code: 'c:\\documents and settings\\user\\my documents\\python projects\\garlicsim\\garlicsim\\test_garlicsim\\'

    (Tarball is here: )

    I checked and I don't have `import settings` or ` .settings` in my test files. I don't know why this happens.

    One suspect I have is the current `test_garlicsim/` module. It has a function that does some dynamic importing. The function takes a Python package and imports all its sub-modules, using `garlicsim.general_misc.import_tools.import_all`. One of the submodules that some of these packages may have is called `settings`. You think this is what's causing this bug?

    (Also: I tried deleting all `.pyc` files in `test_garlicsim` and all its subfolders, but it didn't solve the problem.)

  10. Ram Rachum

    Also, in parallel to solving this problem, maybe it's possible to make `coverage` fail gracefully when it can't find a source file instead of messing up the whole html report?

  11. Ned Batchelder repo owner

    I'd like to get to the bottom of why coverage thinks these files exist when they don't, or vice-versa. But in the meantime, the -i switch to coverage html will tell it to ignore errors like these.

  12. Ned Batchelder repo owner

    Running your new tarball, I can reproduce your missing file. The output of "coverage debug data | grep" shows what's going on. It mentions 10 files that actually exist, then ends with:

    /tmp/temp_garlicsim_gWXgpH/_coin_flip/ 2 lines

    This is due to test_garlicsim/test_doc/test_tutorial_2/, which creates a tempfile with prefix "temp_garlicsim_". The temp dir is removed at the end of the test, of course, so the file no longer exists for coverage ro use in reporting. The -i switch is the right way to deal with this situation.

  13. Ram Rachum

    Haha, that is quite hairy :)

    Though I don't think this is the end of this bug, since it has happened a few times, from before I wrote stuff using `tempdir`. If it'll come up again in something which doesn't involve `tempdir` I'll let you know.

    Thanks for diving in Ned.

  14. Log in to comment