Testing Plugins with pytester

Plugins are code that needs to be tested just like any other code. However, testing a change to a testing tool is a little tricky. When we tested the plugin manually with test_slow.py, we

  • ran with -v to make sure the slow marked test was skipped,
  • ran with -v --slow to make sure both tests ran, and
  • ran with -v -m slow --slow to make sure just the slow test ran.

We’re going to automate those tests with the help of a plugin called pytester. pytester ships with pytest but is disabled by default. The first thing we need to do then, is to enable it in conftest.py:

 pytest_plugins = [​"pytester"​]

Now we can use pytester to write our test cases. pytester creates a temporary directory ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.