From the course: Unit Testing and Test Driven Development in Python

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

An xunit-style setup and teardown

An xunit-style setup and teardown

- [Instructor] In this lecture, I'm going to give you an overview of pytest support for the xUnit style of setup and teardown functions. One key feature of all unit test frameworks is providing the ability to execute setup code before and after the test. pytest provides this capability with both xUnit-style setup and teardown functions and with pytest fixtures. The xUnit-style setup and teardown functions allow you to execute code before and after test modules, test functions, test classes, and test methods in test classes. Using these setup and teardown functions can help reduce code duplication by letting you specify the setup and teardown code once at each of the different levels as necessary rather than repeating the code in each individual unit test. This can help keep your code clean and manageable. Let's look at some examples to see how this works. In the first example, I'm going to look at setup and teardown of individual unit test functions that are not in a class. I've got…

Contents