views:

179

answers:

2

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!

+1  A: 

I feel really dirty suggesting this, but

import pylint.lint
import sys

original_exit = sys.exit

def no_exit():
    pass

try:
    sys.exit = no_exit
    pylint.lint.something(__file__, justerrors=True)
finally:
    sys.exit = original_exit
Blair Conrad
:D ... I will try this one, but it doesn't really solve the issue: I have my ~/.pylintrc which is used when I invoke pylint from the command line, but when I run it programmatically, I only want errors (and possibly warnings). but thanks, it can serve as a start.
mariotomo
Sorry, I'm not that pylint-aware, and focussed on your sys.exit problem.
Blair Conrad
A: 

take a look at the pylint/epylint.py which contains two different ways to start pylint programatically.

You can also simply use call Run('--errors-only', 'myfile.py') for instance.

syt
combined with previous answer. and with slight modification: `pylint.lint.Run(['--errors-only', filename])`
mariotomo