Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page