Writing tests

Python has a number of different testing libraries available. The default library that comes with Python is unittest. This library is based on JUnit, from Java, and it shows. In this my opinion, the library is not especially user friendly, and there are 12 different tests to choose from, based on the expected outcome of the code. Writing the tests isn't especially intuitive for beginners, partly because of the amount of boilerplate code required just to work with unittest.

While nose2 is available as a third-party testing library, a more popular option is pytest. It requires no boilerplate; most of the time, just having pytest installed on your system is sufficient, though, in some cases, an explicit import of pytest is required. ...

Get Learn Programming in Python with Cody Jackson 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.