23 Jan 2020.

Tags: Test Development

Pylint is a static analysis tool for Python code. This means that it analyses your code to catch common mistakes, without actually running your code. This saves a lot of development time by catching the mistakes immediately —your IDE shows red squiggles under each mistake— instead of running the test and waiting for it to reach the line of code where the mistake is.

Stb-tester provides a Pylint plugin that teaches Pylint about some mistakes that are specific to Stb-tester APIs. For example, the frame parameter of stbt.match is usually optional, but it’s mandatory when called inside a FrameObject property:

stbt.match('home.png') missing 'frame' argument - pylint(stbt-frame-object-missing-frame)
VS Code showing an error caught by static analysis

Another common mistake is using a reference image that doesn’t exist on disk, or that hasn’t been committed to git:

Image 'tests/appletv/home/YouTube.png' not committed to git - pylint(stbt-uncommitted-image)
Forgetting to commit the reference image is a frustrating mistake — but not if you catch it immediately!

Some Stb-tester APIs raise an exception on failure (for example stbt.wait_for_match) but others don’t (for example stbt.match and stbt.wait_until, among others). This can be confusing, so we report an error if you forget to use the return value from the latter group of APIs:

'stbt.wait_until' return value not used (missing 'assert'?) - pylint(stbt-unused-return-value)
If you don't check the return value from stbt.wait_until, it's probably a mistake

Disabling Pylint warnings

In some rare cases you might want to ignore the return value for a valid reason. You can disable the warning for that specific line, by adding a comment like this:

# pylint:disable=stbt-unused-return-value
Disable the warning on this line (but do warn me if I forget to check the return value in other places!)

Some of Pylint’s built-in checks are related to coding style, not real problems. If they get annoying you can disable specific checks by listing them in the .pylintrc file in the root of your test-pack. For example:

[MESSAGES CONTROL]
disable=
  line-too-long,
  missing-docstring,

The name of each checker (such as “line-too-long”) is shown after the error message in your IDE.

IDE Configuration

To set up your IDE to catch all of these errors, see IDE Configuration in the Stb-tester manual.

If you’re curious about the full list of checks that Stb-tester adds to Pylint, see the source code of our Pylint plugin here.