Coverage not creating any output file

Issue #232 invalid
jalder created an issue

When I try to run a component test of our testing framework, coverage is not willing to produce any output file (.coverage) and thus failes to generate a report. Apart from this, coverage is not reporting any errors.

qauser@foqa01:~/.jenkins/workspace/TAF-Test> coverage run TestCases/TAF/ComponentTests/
qauser@foqa01:~/.jenkins/workspace/TAF-Test> coverage xml
No data to report.

As this is our framework for component tests up to system integration tests there is quite some stuff happening in there... Do you have any advice on how to track this issue? Is there any verbose mode for coverage?

If I run coverage with a simple script it works perfectly, so the installation seems fine.

qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> coverage debug sys
-- sys ----------------------------------------
        version: 3.6
       coverage: /usr/local/lib64/python2.6/site-packages/coverage-3.6-py2.6.egg/coverage/__init__.pyc
      cover_dir: /usr/local/lib64/python2.6/site-packages/coverage-3.6-py2.6.egg/coverage
     pylib_dirs: /usr/lib64/python2.6
         tracer: PyTracer
   config_files: .coveragerc
   configs_read: -none-
      data_path: /export/home/qauser/.jenkins/workspace/TAF-Test/.coverage
         python: 2.6 (r26:66714, Nov  9 2010, 01:31:57) [GCC 4.3.4 [gcc-4_3-branch revision 152973]]
       platform: Linux-
 implementation: CPython
     executable: /usr/bin/python2.6
            cwd: /export/home/qauser/.jenkins/workspace/TAF-Test
           path: /usr/local/bin
    environment: PYTHONPATH = .:/export/home/qauser/.jenkins/workspace/TAF-Test
                 PYTHONSTARTUP = /etc/pythonstart
                 PYTHONPATHBASE = /export/home/qauser/.jenkins/workspace/TAF-Test

PS: Thanks for all of this and keep up the good work!

Comments (15)

  1. jalder reporter

    I just noticed that if the execution of our test produces an exception (still handled inside the framework) coverage is producing an output file.

    Any ideas how to track this issue? What calls could influence coverage like this?

  2. Ned Batchelder repo owner

    The only odd thing I see in the "debug sys" output is that you are using PyTracer instead of CTracer, it looks like you couldn't compile the C extension on installation. That shouldn't produce the problem you are seeing, but you'll want to fix that, because it will slow down your test runs.

    Are you using any libraries for starting or stopping processes, or using exotic multi-threading techniques? A few of these are listed at Anything unusual that you might be using in your library might be a clue.

  3. jalder reporter

    Just fixed the CTracer, thanks for the hint.

    I searched the code again and found some process stuff (multiprocessing (bad), subprocess (ok?), threading (ok?)) but those are all in some implementation classes and not in the framework code i execute with the component tests mentioned here.

    Apart from those I couldn't find any unusual modules.

    I'm really wondering why coverage isn't producing any data at all. Is this the default behavior if no executed code is traced?

  4. Ned Batchelder repo owner

    Coverage will say "No data to report" if there is no data collected. Can you show the result of "coverage debug data" after your "coverage run .." command?

  5. jalder reporter

    Here you are..

    qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> coverage run TestCases/TAF/ComponentTests/
    qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> coverage debug data
    -- data ---------------------------------------
    path: /export/home/qauser/.jenkins/workspace/TAF-Test/.coverage
    has_arcs: False
    No data collected
    qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> ls -la ./.coverage
    ls: cannot access ./.coverage: No such file or directory
    qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> ls -la .coverage
    ls: cannot access .coverage: No such file or directory
  6. Ned Batchelder repo owner

    Is it possible that your program is interfering with writing the .coverage data file? When I run coverage and collect no data, I get a 48-byte .coverage file anyway, and also a warning during the run phases, "No data was collected". Is there any chance you can share the code your are running?

  7. jalder reporter

    Hey Ned. Sorry for the late response. Unfortunately I'm pretty busy with other stuff at work right now and I won't get back to the lovely python coding in the next days. I'll provide more information as soon as I can.

  8. Sorin Ionuț Sbârnea

    The problem is quite simple, if any of the tests are changing the current directory, coverage will end-up using the wrong directory.

    The only solution to this is to make coverage determine the output directory before starting the tests.

  9. Ned Batchelder repo owner

    Sorin: that's not true. The "debug sys" output shows the path that coverage will use for the data file, even if the tests change the directory. Have you encountered problems with a changed directory? used to have a problem with changing directories, but it's been fixed for 3.5 years: see issue #24.

  10. Mark Evans

    I have seen the .coverage file fail to be generated in our project (we import coverage and start()/stop() it programmatically). I have not fully debugged it, but what was happening was that Coverage._atexit handler was not being called in some scenarios. I've worked around it by explicitly calling save() and not relying on the atexit handler even though auto_data is True.

    Our project is rather complex, so I can't provide a simple code sample yet (and it seemed timing dependent.) We do have atexit handlers of our own as well as signal handlers.

    If I learn more, I'll pass it on. Just like everyone, I'm in the middle of a release cycle so it may be a while before I can look more deeply into it. :)

  11. todd staples

    i'm having a similar issue over here .. but only in my container. Figured i'd share hoping that maybe someone will see this and know what is going on. Probably going to post this on stackoverflow at this point too cause i'm baffled.

    Basically my situation is this. I'm starting a python based (pyramid) web services app. Simple enough. I want to get coverage numbers on it so I start it by doing "coverage run /path/path/path/". Again.. simple enough.

    We just created a container for this.. so now i want to do the same thing inside the container.. get the coverage information after testing the web services as they're running in the container, run a report, and then stop the container. Shouldn't be a huge issue... BUT IT IS!

    If i build the container with an ENTRYPOINT or CMD starting the app.. like these.. and yes i've tried them all..

    ENTRYPOINT coverage run /path/path/path/ ENTRYPOINT bash -c "coverage run /path/path/path/" ENTRYPOINT ["bash' "-c","coverage run /path/path/path/"] ENTRYPOINT ["coverage","run","/path/path/path/"] CMD coverage run /path/path/path/ CMD ["bash' "-c","coverage run /path/path/path/"] or CMD ["coverage","run","/path/path/path/"]

    and then start the container like this

    docker run --name stage1-latest-container-instance -itp 56432:56432 stage1-latest

    or even this in the case of the CMD entries in the dockerfile (since they're default, and i'm overriding them with this command)

    docker run --name stage1-latest-container-instance -itp 56432:56432 stage1-latest coverage run /path/path/path/

    my app starts perfectly fine.. works no problem.. BUT

    no .coverage file is created! no where in the container do i see a .coverage file..

    Ok.. trying a diff approach

    Keep just ENTRYPOINT bash or CMD bash in the dockerfile

    rebuild it...

    And then run the container with docker run --name stage1-latest-container-instance -itp 56432:56432 stage1-latest

    which gives me a prompt in the docker container. [root@ac25fb69bb2e /]#

    Then from another window do this

    docker exec -it stage1-latest-container-instance coverage run /path/path/path/ or many other ways to do this docker exec like docker exec -it stage1-latest-container-instance bash -c "coverage run /path/path/path/"

    STILL! no .coverage file gets created.

    I've even created a file called and put the following lines in it

    cd /path/path/path && coverage run 

    and then started the container with

    docker run --name stage1-latest-container-instance -itp 56432:56432 stage1-latest /path/

    and tried docker exec -it stage1-latest-container-instance /path/

    still no .container file

    ok.. last resort..

    go into the prompt that I got after i ran the "docker run" with just "CMD bash" in the dockerfile in interactive mode (-it).. and start my app with coverage in there manually.

    [root@ac25fb69bb2e /]# coverage run /path/path/path/

    AND AMAZINGLY.. the .coverage file is created no problem....

    WHAT THE HECK! i cannot figure this one out.. it has to have something to do with docker container layering of commands or something.. or permissions.. no clue.. but i'm frustrated as all hell. Figured i'd contribute to this thread as its the only one i've been able to find so far that discusses the .coverage data file not getting created.

  12. Log in to comment