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

Combining Markers with Fixtures

Markers can be used in conjunction with fixtures. They also can be used in conjunction with plugins and hook functions (but that’s a topic for Chapter 15, Building Plugins). Here, we’ll combine markers and fixtures to help test the Cards application.

The builtin markers took parameters, while the custom ones we’ve used so far do not. Let’s create a new marker called num_cards that we can pass to the cards_db fixture.

The cards_db fixture currently cleans out the database for each test that wants to use it:

 @pytest.fixture(scope=​"function"​)
 def​ ​cards_db​(session_cards_db):
  db = session_cards_db
  db.delete_all()
 return​ db

If we want to, say, have three cards in the ...

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