3

I am trying to run PyLint and need a setup where it only fails if the SEVERITY='ERROR' and also I still want to see and logs as in all severity level messages. I tried with --fail-on=E but it still fails. I run the command below:

pipenv run python3 -m pylint --fail-on=E src/app src/backend --output-format=teamcity.pylint_reporter.TeamCityReporter

Currently I get this error: Error 28

Is there a way to achieve this?

3 Answers 3

1

The pylint exit code is byte encoded depending on what was raised:

Fatal (1)
Error (2)
Warning (4)
Convention (8)
Refactor (16)
Information (NA)

See https://pylint.readthedocs.io/en/latest/user_guide/messages/index.html

It means in your case an okay output would be 4 (warning only), 8 (convention only), 12 (warning and convention), 16 (refactor only), 20 (warning and refactor), 24 (convention and refactor), or 28 (convention refactor and warning).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for clarification. I went through the same list as well. Now the issue is I don't want PyLint to fail until its ERROR.
You should do that in bash (if exit in 4,812,16,20,24,28...) or by using allow_failure in your continuous integration. What you want to do is not doable in pylint directly I can't find the issue with the reasoning but both cannot be true at the same time (probably in part because pylint options for that are already pretty complicated already and for perf reason because no need to calculate something you're never going to look at). Either you use --error-only and get only error message or you don't and you get all messages.
1

It might still fail when other messages are printed because all messages lower the score. The default behaviour is: if the score is less than 10, the exit code will be non-zero — see --fail-under:

Specify a score threshold under which the program will exit with error.

Default: 10

To get it to only fail on errors, but still show other messages, try this:

pylint src/app --fail-under 5 --fail-on E

Comments

1

TLDR; you can achieve it by doing pylint src/app src/backend; if [ $(( $? & 2 )) -eq 2 ]; then exit 1; else exit 0; fi

As we can see in @pierre-sassoulas's answer, Pylint's exit codes can be represented in binary as:

Fatal       (1)  - 00001
Error       (2)  - 00010
Warning     (4)  - 00100
Convention  (8)  - 01000
Refactor    (16) - 10000
Information (NA)

Pylint outputs the sum of the message categories found. So anything that has an error will have the second bit (counting from the right) with a 1. We can figure out if there were any errors in the Pylint report using the bitwise AND operator.

pylint src/app src/backend; if [ $(( $? & 2 )) -eq 2 ]; then exit 1; else exit 0; fi

We first run pylint, and then check if the bitwise AND operator between Pylint's exit code and 2 is equal to 2. If it is, then an error was found in the report, and the exit code of the command will be 1, otherwise the exit code is 0.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.