Chapter 3

Utilizing Unit Test Tools

YOU HAVE STARTED to write your unit tests and feel comfortable running them in the usual manner for executing Python files. However, with testing as much a part of the development process as writing the code itself, it is natural that many tools have surfaced to aid and assist in the running of unit tests as part of the daily development cycle. Whether it be to aid writing the test files themselves or to make running the tests and debugging easier, the tools available help to make you a more productive developer who is better able to build testing into processes such as continuous integration.

This chapter introduces the tools that enable you to work in a better way with your unit testing, giving you useful features such as one-line commands for running your unit tests. You will look at using commonplace tools such as Nosetest and PyTest for running your unit tests and the helpful output and features they provide to make testing easier. I will also cover the integration of these runners with other advanced tools such as coverage reporting and coding style reports. These tools show whether or not lines of code are covered by tests and the lines of code that break coding conventions as outlined in PEP-8. Finally, the chapter finishes by demonstrating the use of mocking and patching within your tests. These strategies allow you to test your application even when making calls to external systems or elements of your application you do not want to ...

Get Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.