Computer Science 203:

Software Engineering

Gregory M. Kapfhammer

Color Scheme

Key Concept

Corresponding Diagram

In-Class Discussion

In-Class Activity

Details in the Textbook

Python Testing with Pytest

Chapters 3 through 4

Pytest Fixtures

Pytest Fixtures

Contain arbitrary Python source code

Used to setup and/or teardown during testing

"Input" to a test function

Single fixture

Multiple fixture



What are the benefits of using fixtures?

Sharing through

What are the benefits of using conftest?

Kinda like making a plugin!

Application to the software project

Builtin Fixtures

Builtin Fixtures

Provided as part of a Pytest distribution

Supports reuse of commonly needed features

Example: tmpdir and tmpdir_factory

"Mocking" when testing

Benefits of "mocking"?

Using tmpdir

Using pytestconfig

Test independence


Benefits of test independence?

Using cache

Using --last-failed

Using --failed-first

We need to maintain test history!

Test suite prioritization

"Put your best test forward"

Reorder the Tests


Fastest tests first

High coverage tests first

High mutation tests first

Combine these strategies

See pages 83 through 85

Using capsys

Changes Pytest's behavior

Application to the software project

Next, learn more about plugins!