Amandasaurus
Amandasaurus

Reputation: 60689

How to write unittests for a custom pylint checker?

I have written a custom pylint checker to check for non-i18n'ed strings in python code. I'd like to write some unittests for that code now.

But how? I'd like to have tests with python code as a string, which will get passed through my plugin/checker and check the output?

I'd rather not write the strings out to temporary files and then invoke the pylint binary on it. Is there a cleaner more robust approach, which only tests my code?

Upvotes: 1

Views: 699

Answers (1)

sthenault
sthenault

Reputation: 15125

Take a look at pylint's test directory. You will find several example there. For instance, unittest_checker_*.py files are all unit-tests for unique checker.

You may also be interested in functional tests: put some input file in test/input and expected message file in test/messages, then python test_func.py should run it. While this is more for pylint's core checker, it may be easily backported in your own project.

Upvotes: 1

Related Questions