Computer Science 203:

Software Engineering

Gregory M. Kapfhammer


Triangles 1 flickr photo by vincentag shared under a Creative Commons (BY-NC-ND) license

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

Setup

Teardown

What are the benefits of using fixtures?

Sharing through conftest.py

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

pytest-randomly

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

Random

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!