invoking pylint programmatically

后端 未结 7 867
难免孤独
难免孤独 2020-12-05 00:21

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

7条回答
  •  感情败类
    2020-12-05 00:45

    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:

    from pylint import epylint
    
    pylint_stdout, pylint_stderr = epylint.py_run(__file__, return_std=True)
    print(pylint_stdout.getvalue())  # -> there is just the final rank, no report nor message
    print(pylint_stderr.getvalue())
    

    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.

    from pylint import epylint
    options = '--enable=all'  # all messages will be shown
    options += '--reports=y'  # also print the reports (ascii tables at the end)
    
    pylint_stdout, pylint_stderr = epylint.py_run(__file__ + ' ' + options, return_std=True)
    print(pylint_stdout.getvalue())
    print(pylint_stderr.getvalue())
    

    As described here, pylint will perform the parsing itself, and will correctly output the expected results in stdout.

提交回复
热议问题