Book Image

pytest Quick Start Guide

By : Bruno Oliveira
Book Image

pytest Quick Start Guide

By: Bruno Oliveira

Overview of this book

Python's standard unittest module is based on the xUnit family of frameworks, which has its origins in Smalltalk and Java, and tends to be verbose to use and not easily extensible.The pytest framework on the other hand is very simple to get started, but powerful enough to cover complex testing integration scenarios, being considered by many the true Pythonic approach to testing in Python. In this book, you will learn how to get started right away and get the most out of pytest in your daily work?ow, exploring powerful mechanisms and plugins to facilitate many common testing tasks. You will also see how to use pytest in existing unittest-based test suites and will learn some tricks to make the jump to a pytest-style test suite quickly and easily.
Table of Contents (9 chapters)

Migration strategy

Being able to run unittest-based tests out of the box is definitely a very powerful feature, because it allows you to start using pytest right away as a runner.

Eventually, you need to decide what to do with the existing unittest-based tests. There are a few approaches you can choose:

  • Convert everything: if your test suite is relatively small, you might decide to convert all tests at once. This has the advantage that you don't have to make compromises to keep existing unittest suites working, and being simpler to be reviewed by others because your pull request will have a single theme.
  • Convert as you go: you might decide to convert tests and functionality as needed. When you need to add new tests or change existing tests, you take the opportunity to convert tests and/or refactor functionality to fixtures using the techniques from the previous sections...