Testing with pytest

Length: 1 day (8 hours)

Description: The “pytest” framework is one of the most popular ways that Python developers test their code — ensuring that the code is robust and maintainable. Pytest’s flexibility makes it easy to start testing, even for people who have never written tests before.

This course introduces experienced Python developers to “pytest“, and shows them how to use it to test a variety of circumstances. After taking this course, you will know how to write tests, how to configure pytest to your needs, and how to both use and write “fixtures” for cleaner test authoring.

Audience: Participants will need at least basic familiarity with Python in order to participate. In particular, they’ll need to understand how to write functions, how to apply (but not write) decorators, and how functions work. They’ll also need to be familiar with using “pip” to install and upgrade packages from PyPI.

No previous knowledge of testing is assumed in this course, although it will certainly be helpful.

As always, this course includes a large number of hands-on exercises to practice configuring and working with pytest.

Participants will receive PDF copies of the slides, files with the answers to exercises, and any other files (configuration, test, and code) I create during the day.

This course, like all of my courses, can be given either in-person or virtually. Contact me for availability and pricing, but be warned that my time tends to fill up months in advance.

Syllabus

  • Installation and use of pytest
  • Testing functions
  • pytest arguments
  • Parametrized tests
  • Capturing input and output
  • Using defined fixtures
  • Fixture scopes
  • Parametrized fixtures
  • Working with external services
  • Working with external files
  • Monkey patching, good and bad
  • Testing classes
  • Code coverage
  • pytest configuration options
  • pytest plugins
>