Travis-CI: Do not fail build because of linter warnings

对着背影说爱祢 提交于 2021-01-24 08:06:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!