0

If I:

  • run a build in travis, and

  • tests pass correctly, but

  • there is some problem uploading coverage results to codecov,

...Travis goes ahead and deploys anyway. How can I stop travis from deploying in this case?

The deploy-regardless-of-upload-failure:

goes ahead and deploys anyway.

Here's my .travis.yml:

dist: trusty
language: python
python:
  - '3.6'

# Install tox and codecov
install:
  - pip install tox-travis
  - pip install codecov

# Use tox to run tests in the matrix of environments
script:
- tox -r

# Push the results back to codecov
after_success:
  - codecov --commit=$TRAVIS_COMMIT"

# Deploy updates on master to pypi, which will only succeed if there's been a version bump
deploy:
  provider: pypi
  skip_cleanup: true
  skip_existing: true
  user: me
  password:
    secure: "stuff"
  on:
    branch: master
thclark
  • 4,784
  • 3
  • 39
  • 65
  • Does this answer your question? [How to get travis to fail if tests do not have enough coverage for python](https://stackoverflow.com/questions/33965755/how-to-get-travis-to-fail-if-tests-do-not-have-enough-coverage-for-python) – Ramon Medeiros Jan 09 '20 at 08:46

1 Answers1

0

According to this https://bitbucket.org/ned/coveragepy/issues/139/easy-check-for-a-certain-coverage-in-tests, if you add the --fail-under switch to the coverage report command, it will exit with a non-zero exit code (which travis will see as a failure) if the code coverage is below the given percentage.

That would make the script section of your .travis.yml file look like:

script
 - coverage run --source="mytestmodule" setup.py test
 - coverage report --fail-under=80

Of course you could replace 80 with whatever percentage you'd like.

Ramon Medeiros
  • 2,272
  • 2
  • 24
  • 41
  • Useful, thank you (I'll add it!), I think this only partially answers the question (it covers the case that a report isn't generated due to zero test coverage). However, my test cases pass with a coverage of 97%, so this wouldn't fail. The issue is that the codecov upload failed because there hadn't been a postprocessing step converting the report to XML. It could fail for any number of other reasons too, e.g. codecov offline, and I'd want that to stop my build. – thclark Jan 10 '20 at 10:09