Learn to write simple but effective tests with Pytest.
From basics to advanced topics with simple, but detailed explanations and example code. Explore the topics below or on the sidebar to get started.
Getting Started
- How To Run Pytest (
python -m pytest
vspytest
) - How To Run Pytest In VS Code (Easy To Follow Step-By-Step Tutorial)
- How To Set Up Pytest With PyCharm (Step-By-Step Guide)
- How To Run Pytest With Poetry (A Step-by-Step Guide)
Basic Concepts
- Maximizing Quality - A Comprehensive Look at Testing in Software Development
- How To Test Python Exception Handling Using Pytest Assert (A Simple Guide)
Running Tests
- How To Run A Single Test In Pytest (Using CLI And Markers)
- How To Filter Tests Effortlessly With Pytest -K Options
Fixtures
- How Pytest Fixtures Can Help You Write More Readable And Efficient Tests
- What Are Pytest Fixture Scopes? (How To Choose The Best Scope For Your Test)
- A Step-by-Step Guide To Using Pytest Fixtures With Arguments
- How to Auto-Request Pytest Fixtures Using “Autouse”
- How To Access Test Details With Pytest Request Fixture
- What is Setup and Teardown in Pytest? (Importance of a Clean Test Environment)
- What Is Pytest Caplog? (Everything You Need To Know)
- How To Manage Temporary Files with Pytest tmp_path
Parametrization
- How to Effortlessly Generate Unit Test Cases with Pytest Parameterized Tests
- A Beginner’s Guide To
pytest_generate_tests
(Explained With 2 Examples)
Mocking
- Common Mocking Problems And How To Avoid Them (+ Best Practices)
- How To Mock In Pytest? (A Comprehensive Guide)
- Mocking Vs. Patching (A Quick Guide For Beginners)
- What Are Pytest Mock Assert Called Methods and How To Leverage Them
- The Ultimate Guide To Using Pytest Monkeypatch with 2 Code Examples
- How To Test Raised Exceptions with Pytest MagicMock? (Advanced Guide)
- How To Return Multiple Values From Pytest Mock (Practical Guide)
- How To Easily Resolve The “Fixture ‘Mocker’ Not Found” Error in Pytest
- How To Mock Celery Tasks With Pytest (Step-by-Step Guide with Examples)
Configuration & Environment Variables
- Pytest Conftest With Best Practices And Real Examples
- What Is
pytest.ini
And How To Save Time Using Pytest Config - Pytest Config Files - A Practical Guide To Good Config Management
- How To Ignore Warnings In Pytest (With Examples)
- 3 Simple Ways To Ignore Test Directories in Pytest
- The Ultimate Guide To Capturing Stdout/Stderr Output In Pytest
- How To Use Pytest With Command Line Options (Easy To Follow Guide)
- 4 Proven Ways To Define Pytest PythonPath and Avoid Module Import Errors
- 3 Simple Ways To Define Environment Variables In Pytest
Markers
Property Based Testing
Async Testing
Flask Testing
FastAPI Testing
- Pytest API Testing with FastAPI, SQLAlchemy, Postgres - 1/2
- Pytest API Testing with FastAPI, SQLAlchemy, Postgres - 2/2
- Building And Testing FastAPI CRUD APIs With Pytest (Hands-On Tutorial)
Django Testing
External API Testing
Database Testing
Web Automation Testing
- How To Use Pytest With Selenium For Web Automation Testing
- Test Automation Made Easy with Pytest and Playwright
- How To Create Interactive Test Reports with Pytest and Allure
Pytest Errors and Debugging
- A Simple Guide to Fixing The ‘Pytest Collected 0 Items’” Error
- 7 Simple Ways To Fix The “Pytest Command Not Found” Error
- 5 Simple Techniques To Resolve The Pytest Fixture Not Found Error
- How To Debug Failing Tests Like A Pro (Use Pytest Verbosity Options)
CI/CD Pipelines
- Automated Python Unit Testing Made Easy with Pytest and GitHub Actions
- How To Test And Build Python Packages With Pytest, Tox And Poetry
Plugins and Integrations
- 8 Useful Pytest Plugins To Make Your Python Unit Tests Easier, Faster and Prettier
- How To Create Custom HTML Test Reports With pytest-html
- Parallel Testing Made Easy With pytest-xdist
- A Simple Guide To Controlling Time in Pytest Using Freezegun
- How To Measure And Improve Code Efficiency with Pytest Benchmark (The Ultimate Guide)
- How To Avoid Hanging Tests Using Pytest Timeout (And Save Compute Resource)
- An Ultimate Guide To Using Pytest Skip Test And XFail - With Examples
- Save Money On You CI/CD Pipelines Using Pytest Parallel (with Example)
- A Comprehensive Guide to Pytest Approx for Accurate Numeric Testing
Coverage
- 3 Simple Ways To Omit Subfolders From Python Coverage Reports
- How To Measure And Improve Test Coverage With Poetry And Pytest
- How To Generate Beautiful & Comprehensive Pytest Code Coverage Reports (With Example)
BDD (Behavior-Driven Development)
TDD (Test-Driven Development)
Hooks
- Introduction To Pytest Hooks (A Practical Guide For Beginners)
- What Is The pytest_configure Hook? (A Simple Guide)
- pytest_sessionstart and pytest_sessionfinish (A Complete Guide)
Testing CLI Applications
Testing AWS Services
Misc
- How To Use Pytest Logging And Print To Console And File (A Practical Guide)
- 5 Easy Ways To Read JSON Input Data In Pytest
Best Practices
- Python Testing 101 (How To Decide What To Test)
- 13 Proven Ways To Improve Test Runtime With Pytest
- Python Unit Testing Best Practices For Building Reliable Applications