Skip to content

Testing with Pytest

Testing with Pytest Book

Chapters

Chapters Checklist

  • Preface
    • What Is pytest?
    • Learn pytest While Testing an Example Application
    • How This Book Is Organized
    • What You Need to Know
    • Example Code and Online Resources
  • 1. Getting Started with pytest
    • Getting pytest
    • Running pytest
    • Running Only One Test
    • Using Options
    • Exercises
    • What’s Next
  • 2. Writing Test Functions
    • Testing a Package
    • Using assert Statements
    • Expecting Exceptions
    • Marking Test Functions
    • Skipping Tests
    • Marking Tests as Expecting to Fail
    • Running a Subset of Tests
    • Parametrized Testing
    • Exercises
    • What’s Next
  • 3. pytest Fixtures
    • Sharing Fixtures Through conftest.py
    • Using Fixtures for Setup and Teardown
    • Tracing Fixture Execution with –setup-show
    • Using Fixtures for Test Data
    • Using Multiple Fixtures
    • Specifying Fixture Scope
    • Specifying Fixtures with usefixtures
    • Using autouse for Fixtures That Always Get Used
    • Renaming Fixtures
    • Parametrizing Fixtures
    • Exercises
    • What’s Next
  • 4. Builtin Fixtures
    • Using tmpdir and tmpdir_factory
    • Using pytestconfig
    • Using cache
    • Using capsys
    • Using monkeypatch
    • Using doctest_namespace
    • Using recwarn
    • Exercises
    • What’s Next
  • 5. Plugins
    • Finding Plugins
    • Installing Plugins
    • Writing Your Own Plugins
    • Creating an Installable Plugin
    • Testing Plugins
    • Creating a Distribution
    • Exercises
    • What’s Next
  • 6. Configuration
    • Understanding pytest Configuration Files
    • Changing the Default Command-Line Options
    • Registering Markers to Avoid Marker Typos
    • Requiring a Minimum pytest Version
    • Stopping pytest from Looking in the Wrong Places
    • Specifying Test Directory Locations
    • Changing Test Discovery Rules
    • Disallowing XPASS
    • Avoiding Filename Collisions
    • Exercises
    • What’s Next
  • 7. Using pytest with Other Tools
    • pdb: Debugging Test Failures
    • Coverage.py: Determining How Much Code Is Tested
    • mock: Swapping Out Part of the System
    • tox: Testing Multiple Configurations
    • Jenkins CI: Automating Your Automated Tests
    • unittest: Running Legacy Tests with pytest
    • Exercises
    • What’s Next