I'd like to invoke the pylint checker, limited to the Error signalling part, as part of my unit testing. so I checked the pylint executable script, got to the pylint.lint.Run
helper class and there I got lost in a quite long __init__
function, ending with a call to sys.exit()
.
anybody ever tried and managed to do so?
the dream-plan would be this:
if __name__ == '__main__':
import pylint.lint
pylint.lint.something(__file__, justerrors=True)
# now continue with unit testing
any hints? other than "copy the __init__
method and skip the sys.exit()
", I mean?
I don't need the tests to be run by pylint
, it might as well be pyflakes
or other software: feel free to suggest alternatives. thanks!
I got the same problem recently. syt is right,
pylint.epylint
got several methods in there. However they all call a subprocess in which python is launched again. In my case, this was getting quite slow.Building from mcarans answer, and finding that there is a flag exit, I did the following
which is about 3 times faster in my case. With this I have been going through a whole project, using full output to check each source file, point errors, and rank all files from their note.
Take a look at the
pylint/epylint.py
which contains two different ways to start pylint programatically.You can also simply call :
for instance.
Instead of creating a WritableObject class we can use StringIO. StringIO contains write method.
Source:
@cdarke 's answer
@mad7777's answer
I'm glad I came across this. I used some of the answers here and some initiative to come up with:
Args in the above is a list of strings eg. ["-r", "n", "myfile.py"]
Another entry point for pylint is the
epylint.py_run
function, that implement the stdout and stderr interception. However, as shown in the following code, pylint seems to not write its reports in stdout:Now, i found that pylint from API and pylint from CLI do not use the same default parameters. So, you just have to provides the parameters you need to pylint.
As described here, pylint will perform the parsing itself, and will correctly output the expected results in stdout.