Testing Python code with pytest
Length: 1 day
Description
From individual hobbyists to the largest corporations, just about everyone agrees that it’s important to test your code. But which testing framework should you use? In the Python world, “pytest” has rocketed to popularity in the last few years — largely because of how easy it is to use and integrate into your software-testing framework.
This course introduces “pytest”, from installation and configuration, through common things you might want to test, to repeating tests, to mocking, fixtures, and other advanced topics. By the end of this day, your developers will not only understand how to test code with pytest, but how to write code that works well with pytest, and is thus more maintainable
By the end of the course, participants should feel comfortable using pytest to check their code — and will understand how to incorporate these tests into a larger project.
A large part of the course will be hands-on exercises, which will help participants to learn and understand the regular expression syntax.
Like all of my courses, this is taught without slides. Instead, I live-code into a Jupyter notebook that is available in real time and which I distribute to participants at the end of the course.
Let’s talk about how to customize this course for your team! Set a meeting at https://savvycal.com/reuven/corp-training.
Audience
Python developers who are familiar with basic Python data types, writing functions, and using modules have enough background to take this course.
Syllabus
• Installing pytest
• Testing functions and classes
• Simple and complex assertions
• Testing for exceptions
• Code coverage
• Parametrized tests
• Built-in fixtures
• Simulating input, capturing output
• Writing your own fixtures
• Working with files, temp files, and file-like objects
• Good pytest style
• Configuration files and command-line arguments
• Add-ons for pytest
•
