Remaining Builtin Fixtures

In this chapter, we’ve looked at the tmp_path, tmp_path_factory, capsys, and monkeypatch builtin fixtures. There are quite a few more. Some we will discuss in other parts of the book. Others are left as an exercise for the reader to research if you find the need for them.

Here’s a list of the remaining builtin fixtures that come with pytest, as of the writing of this edition:

  • capfd, capfdbinary, capsysbinary—Variants of capsys that work with file descriptors and/or binary output
  • caplog—Similar to capsys and the like; used for messages created with Python’s logging system
  • cache—Used to store and retrieve values across pytest runs. The most useful part of this fixture is that it allows for --last-failed, --failed-first ...

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.