test-reporter
test-reporter copied to clipboard
Coverage.py formatter gives EOF error
$ py.test --cov=<mypackage
$ ./cc-test-reporter format-coverage -d -t coverage.py -o - .coverage
DEBU[0000] coverage path .coverage
DEBU[0000] using formatter coverage.py
DEBU[0000] checking search path .coverage for coverage.py formatter
DEBU[0000] couldn't load branch from ENV, trying git...
DEBU[0000] couldn't load commit sha from ENV, trying git...
DEBU[0000] couldn't load committed at from ENV, trying git...
Error: EOF
Usage:
cc-test-reporter format-coverage [flags]
Flags:
--add-prefix string add this prefix to file paths
-t, --input-type string type of input source to use [simplecov, lcov, coverage.py, clover, gocov, gcov, cobertura, jacoco]
-o, --output string output path (default "coverage/codeclimate.json")
-p, --prefix string the root directory where the coverage analysis was performed (default "/home/halkeye/git/sauce/it-signups-trial")
Global Flags:
-d, --debug run in debug mode
$ ls -l .coverage
-rw-rw-r-- 1 halkeye halkeye 1523 Oct 24 20:41 .coverage
The error is just "Error: " so not very descriptive
Okay, I figured out this is because the default format is not supported
py.test --cov=<mypackage> --cov-report xml
./cc-test-reporter format-coverage -d -t coverage.py
DEBU[0000] using formatter coverage.py
DEBU[0000] checking search path for coverage.py formatter
DEBU[0000] checking search path coverage.xml for coverage.py formatter
DEBU[0000] couldn't load branch from ENV, trying git...
DEBU[0000] couldn't load commit sha from ENV, trying git...
DEBU[0000] couldn't load committed at from ENV, trying git...
INFO[0000] triming with prefix <current_directory>
DEBU[0000] getting fallback blob_id for source file __init__.py
ERRO[0000] failed to read file __init__.py
open __init__.py: no such file or directory
Error: open __init__.py: no such file or directory
Usage:
cc-test-reporter format-coverage [flags]
i've been trying --add-prefix thingie, but passing my module directory and the full path to it doesn't seem to work
okay, had to eventually run it without mypackage
py.test --cov=. --cov-report xml
Now things work, so it looks like <source> is ignored in the xml
If i ran it with --cov=mypackage
it has <package name="."> not the package name like
https://github.com/codeclimate/test-reporter/blob/master/formatters/coveragepy/example.xml#L5-L9
@halkeye A new release was made recently with the goal of addressing this issue https://github.com/codeclimate/test-reporter/blob/master/CHANGELOG.md#v032-2017-10-30. Let me know if you try and resolves the error you were having.
awesome! I worked around the problem, but I'll try to get it tested with the new stuff asap.
I'm having an issue with this also. When running locally, all is fine. But I'm actually running my tests (pytest + pytest-cov) in a Docker container, so my <source> tag is pointing to something that doesn't exist on the host system (I'm running cc-test-reporter from the host). From the docs I would assume setting --prefix to fix this, but it doesn't seem to matter what I put there (I guess the value is overwritten by the coverage.py <source> parser?).
I can think of a few possible workarounds:
- remove
<source>tag, and use --prefix (not sure if it will work at all?) - run
cc-test-reporterfrom the Docker container (will be very dirty, as I have to pass e.g. all the Travis env vars and deal with test exit code, and propagate it again after cc-test-reporter). - replace
<source>contents with the directory on the host system, usingsedor something. I will go for this, as it seems to me a failsafe semi-clean workaround.
Edit:
Third option did work. Actually, since I'm running coverage only for my source directory (e.g. <repo root>/my_app_source), I'm running pytest like this:
pytest --cov=my_app_source --cov-report=xmlTo get CodeClimate to work properly, set<source>to this folder:<source>my_app_source</source>. I did this withsed, so my.travis.ymllooks like this:
install:
- docker-compose -f docker-compose_test.yml build test
before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- docker-compose -f docker-compose_test.yml run --name app_test test
after_script:
- docker cp app_test:/app/coverage.xml ./coverage_docker.xml
- docker-compose -f docker-compose_test.yml down
- cat coverage_docker.xml | sed "s|<source>.*</source>|<source>my_app_source</source>|" > coverage.xml
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@halkeye A new release was made recently with the goal of addressing this issue https://github.com/codeclimate/test-reporter/blob/master/CHANGELOG.md#v032-2017-10-30. Let me know if you try and resolves the error you were having.
I can confirm that this is not fixed and the only currently workaround is to use sed.