Modern Python Testing
Published by O'Reilly Media, Inc.
Pytest and AI-generated tests
What you’ll learn and how you can apply it
- Write unit tests for Python code
- Write basic functional tests for Python code
- Generate Python tests using LLMs such as DeepSeek, Claude, Chat GPT, etc.
- Recall best practices to parametrize existing tests
- Create custom fixtures in pytest
Course description
In today’s generative AI era, automated testing is crucial. AI tools often produce syntactically correct but logically flawed code with subtle bugs. Using automated testing with pytest provides an essential safety net. With automated testing, developers can catch issues early and ensure future updates don’t break functionality.
Join expert Trey Hunner to discover how to write automated tests for code using pytest, the most popular Python testing framework. You’ll explore good testing practices and learn how to apply them with pytest. You’ll also learn how to generate tests using LLMs.
This live event is for you because...
- You’re a Python user.
- You’re manually testing your Python code and want to start automating your testing process.
Prerequisites
- The ability to create functions and modules in Python
Recommended preparation:
- Explore Python Essentials (on-demand course)
Recommended follow-up:
- Take Write Python Code with ChatGPT and Claude (live online course with Trey Hunner)
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Introduction (50 minutes)
- Presentation: Testing basics; pytest
- Hands-on exercise: Write basic tests
- Q&A
- Break
Debugging (20 minutes)
- Presentation: The Python Debugger (PDB)
- Hands-on exercise: Explore the PDB
- Q&A
Writing tests with LLMs (30 minutes)
- Presentation: Using LLMs to write automated tests
- Hands-on exercise: Generate tests using DeepSeek, Claude, Chat GPT, etc.
Output and assertions (40 minutes)
- Presentation: Expecting exceptions; capturing standard output
- Hands-on exercise: Explore exceptions and outputs
- Break
Monkey patching (30 minutes)
- Presentation: Fixtures for monkey patching
- Hands-on exercise: Use monkey patching in tests
Parametrization (30 minutes)
- Presentation: Parametrization
- Hands-on exercise: Parametrize existing tests
Creating fixtures (30 minutes)
- Presentation: Custom fixtures
- Hands-on exercise: Create your own fixture
Wrap-up and Q&A (10 minutes)
- Presentation: Tips for using pytest
Your Instructor
Trey Hunner
Trey Hunner helps Python programmers level up their skills through corporate training and through Python Morsels, a Python skill-building service for individuals and small teams. Trey also sends out a new Python tip every week through his email newsletter at pym.dev/newsletter.