Early praise for Python Testing with pytest
I found Python Testing with pytest to be an eminently usable introductory guidebook to the
pytest testing framework. It is already paying dividends for me at my company.
→ Chris Shaver
VP of Product, Uprising Technology
Systematic software testing, especially in the Python community, is often either completely
overlooked or done in an ad hoc way. Many Python programmers are completely unaware of the
existence of pytest. Brian Okken takes the trouble to show that software testing with pytest is
easy, natural, and even exciting.
→ Dmitry Zinoviev
Author of Data Science Essentials in Python
This book is the missing chapter absent from every comprehensive Python book.
→ Frank Ruiz
Principal Site Reliability Engineer, Box, Inc.
Author(s): Brian Okken
Series: The pragmatic programmers
Publisher: Pragmatic Bookshelf
Year: 2017
Language: English
Commentary: Conversion
Pages: 256
Tags: python testing pytest
1. Acknowledgments
2. Preface
1. What Is pytest?
2. Learn pytest While Testing an Example Application
3. How This Book Is Organized
4. What You Need to Know
5. Example Code and Online Resources
3. 1. Getting Started with pytest
1. Getting pytest
2. Running pytest
3. Running Only One Test
4. Using Options
5. Exercises
6. What’s Next
4. 2. Writing Test Functions
1. Testing a Package
2. Using assert Statements
3. Expecting Exceptions
4. Marking Test Functions
5. Skipping Tests
6. Marking Tests as Expecting to Fail
7. Running a Subset of Tests
8. Parametrized Testing
9. Exercises
10. What’s Next
5. 3. pytest Fixtures
1. Sharing Fixtures Through conftest.py
2. Using Fixtures for Setup and Teardown
3. Tracing Fixture Execution with –setup-show
4. Using Fixtures for Test Data
5. Using Multiple Fixtures
6. Specifying Fixture Scope
7. Specifying Fixtures with usefixtures
8. Using autouse for Fixtures That Always Get Used
9. Renaming Fixtures
10. Parametrizing Fixtures
11. Exercises
12. What’s Next
6. 4. Builtin Fixtures
1. Using tmpdir and tmpdir_factory
2. Using pytestconfig
3. Using cache
4. Using capsys
5. Using monkeypatch
6. Using doctest_namespace
7. Using recwarn
8. Exercises
9. What’s Next
7. 5. Plugins
1. Finding Plugins
2. Installing Plugins
3. Writing Your Own Plugins
4. Creating an Installable Plugin
5. Testing Plugins
6. Creating a Distribution
7. Exercises
8. What’s Next
8. 6. Configuration
1. Understanding pytest Configuration Files
2. Changing the Default Command-Line Options
3. Registering Markers to Avoid Marker Typos
4. Requiring a Minimum pytest Version
5. Stopping pytest from Looking in the Wrong Places
6. Specifying Test Directory Locations
7. Changing Test Discovery Rules
8. Disallowing XPASS
9. Avoiding Filename Collisions
10. Exercises
11. What’s Next
9. 7. Using pytest with Other Tools
1. pdb: Debugging Test Failures
2. Coverage.py: Determining How Much Code Is Tested
3. mock: Swapping Out Part of the System
4. tox: Testing Multiple Configurations
5. Jenkins CI: Automating Your Automated Tests
6. unittest: Running Legacy Tests with pytest
7. Exercises
8. What’s Next
10. A1. Virtual Environments
11. A2. pip
12. A3. Plugin Sampler Pack
1. Plugins That Change the Normal Test Run Flow
2. Plugins That Alter or Enhance Output
3. Plugins for Static Analysis
4. Plugins for Web Development
13. A4. Packaging and Distributing Python Projects
1. Creating an Installable Module
2. Creating an Installable Package
3. Creating a Source Distribution and Wheel
4. Creating a PyPI-Installable Package
14. A5. xUnit Fixtures
1. Syntax of xUnit Fixtures
2. Mixing pytest Fixtures and xUnit Fixtures
3. Limitations of xUnit Fixtures