问题
I have an old python project that I am trying to progressively clean up using flake8 (to warn about PEP8 issues). I use Travis for continuous integration and want my build to fail if any unit test fails. However, I do not want my build to fail simply because flake8 produced a warning (e.g., about something minor like trailing white space).
How do I configure Travis to output flake8 warnings (so that I can resolve them as I have time) without causing them to fail the build?
My .travis.yml is below:
language: python
python:
- "3.6"
install:
- pip install -r requirements.txt
- pip install flake8
script:
- python -m unittest discover -v
- flake8 .
Example flake8 warnings:
./meta-db/file_system.py:103:80: E501 line too long (108 > 79 characters)
./meta-db/file_system.py:106:68: W291 trailing whitespace
回答1:
Adding --exit-zero flag to flake8 allows lint warnings/errors to be displayed without failing the Travis build.
script:
- python -m unittest discover -v
- flake8 . --exit-zero # Exit with status code "0" even if there are errors.
回答2:
You could have flake8 only check the most recent commit(s) such that you're validating the recent changes are compliant instead of the whole project. Once you're confident, e.g.,
script:
- python -m unittest discover -v
- git diff -U0 $TRAVIS_COMMIT_RANGE | flake8 --diff
- flake8 . --exit-zero
Once that last command stops printing errors, you can trim the --exit-zero
来源:https://stackoverflow.com/questions/53966072/travis-ci-do-not-fail-build-because-of-linter-warnings