Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage not creating any output file #232

Closed
nedbat opened this issue Jan 10, 2013 · 14 comments
Closed

Coverage not creating any output file #232

nedbat opened this issue Jan 10, 2013 · 14 comments
Labels
bug Something isn't working run

Comments

@nedbat
Copy link
Owner

nedbat commented Jan 10, 2013

Originally reported by jalder (Bitbucket: jalder, GitHub: jalder)


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.

#!shell
qauser@foqa01:~/.jenkins/workspace/TAF-Test> coverage run TestCases/TAF/ComponentTests/CT_AlmApi.py
..<output>..
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.

#!shell

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 (bb)](https://bitbucket.org/ned/coveragepy/commits/152973)]]
       platform: Linux-2.6.32.27-0.2-default-x86_64-with-SuSE-11-x86_64
 implementation: CPython
     executable: /usr/bin/python2.6
            cwd: /export/home/qauser/.jenkins/workspace/TAF-Test
           path: /usr/local/bin
                 /usr/local/lib64/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
                 /usr/local/lib64/python2.6/site-packages/coverage-3.6-py2.6.egg
                 /usr/local/lib64/python2.6/site-packages/distribute-0.6.34-py2.6.egg
                 /export/home/qauser/.jenkins/workspace/TAF-Test
                 /usr/lib/python26.zip
                 /usr/lib64/python2.6
                 /usr/lib64/python2.6/plat-linux2
                 /usr/lib64/python2.6/lib-tk
                 /usr/lib64/python2.6/lib-old
                 /usr/lib64/python2.6/lib-dynload
                 /usr/lib64/python2.6/site-packages
                 /usr/local/lib64/python2.6/site-packages
                 /usr/local/lib64/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info
                 /usr/lib64/python2.6/site-packages/gtk-2.0
    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!


@nedbat
Copy link
Owner Author

nedbat commented Jan 14, 2013

Original comment by jalder (Bitbucket: jalder, GitHub: jalder)


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?

@nedbat
Copy link
Owner Author

nedbat commented Jan 14, 2013

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 http://nedbatchelder.com/code/coverage/trouble.html Anything unusual that you might be using in your library might be a clue.

@nedbat
Copy link
Owner Author

nedbat commented Jan 14, 2013

Original comment by jalder (Bitbucket: jalder, GitHub: jalder)


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?

@nedbat
Copy link
Owner Author

nedbat commented Jan 14, 2013

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?

@nedbat
Copy link
Owner Author

nedbat commented Jan 15, 2013

Original comment by jalder (Bitbucket: jalder, GitHub: jalder)


Here you are..

#!shell

qauser@mqzhlfoqa01:~/.jenkins/workspace/TAF-Test> coverage run TestCases/TAF/ComponentTests/CT_AdmMdMessages.py
...<output>...
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

@nedbat
Copy link
Owner Author

nedbat commented Jan 15, 2013

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?

@nedbat
Copy link
Owner Author

nedbat commented Feb 5, 2013

Original comment by jalder (Bitbucket: jalder, GitHub: jalder)


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.

@nedbat
Copy link
Owner Author

nedbat commented Apr 16, 2013

Original comment by Sorin Sbarnea (Bitbucket: sorin, GitHub: sorin)


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.

@nedbat
Copy link
Owner Author

nedbat commented Apr 22, 2013

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?

Coverage.py used to have a problem with changing directories, but it's been fixed for 3.5 years: see issue #24.

@nedbat
Copy link
Owner Author

nedbat commented Apr 22, 2013

jalder: any more information?

@nedbat
Copy link
Owner Author

nedbat commented Sep 15, 2014

Original comment by Mark M Evans (Bitbucket: markmevans, GitHub: markmevans)


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. :)

@nedbat
Copy link
Owner Author

nedbat commented Apr 26, 2015

Feel free to re-open this issue if you get more information.

@nedbat
Copy link
Owner Author

nedbat commented Feb 8, 2018

Original comment by todd staples (Bitbucket: Toddstaples, GitHub: Toddstaples)


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/app.py". 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/app.py
ENTRYPOINT bash -c "coverage run /path/path/path/app.py"
ENTRYPOINT ["bash' "-c","coverage run /path/path/path/app.py"]
ENTRYPOINT ["coverage","run","/path/path/path/app.py"]
CMD coverage run /path/path/path/app.py
CMD ["bash' "-c","coverage run /path/path/path/app.py"]
or
CMD ["coverage","run","/path/path/path/app.py"]

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/app.py

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/app.py
or many other ways to do this docker exec like
docker exec -it stage1-latest-container-instance bash -c "coverage run /path/path/path/app.py"

STILL! no .coverage file gets created.

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

#!bash

#!/bin/bash
cd /path/path/path && coverage run app.py 

and then started the container with

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

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

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/app.py

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.

@nedbat
Copy link
Owner Author

nedbat commented Feb 9, 2018

Original comment by todd staples (Bitbucket: Toddstaples, GitHub: Toddstaples)


figured out a fix for my issue.. please check it out over on stackoverflow if interested

[https://stackoverflow.com/questions/48692363/coverage-run-app-py-inside-a-docker-container-not-creating-coverage-file/48710256#48710256](Link URL)

@nedbat nedbat closed this as completed Feb 9, 2018
@nedbat nedbat added major bug Something isn't working run labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working run
Projects
None yet
Development

No branches or pull requests

1 participant