O'Reilly logo

Python: Journey from Novice to Expert by Rick van Hattem, Dusty Phillips, Fabrizio Romano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing with py.test

The py.test tool makes it very easy to write tests and run them. There are a few other options such as nose and the bundled unittest module available, but the py.test library offers a very good combination of usability and active development. In the past, I was an avid nose user but have since switched to py.test as it tends to be easier to use and has better community support, in my experience at least. Regardless, nose is still a good choice, and if you're already using it, there is little reason to switch and rewrite all of your tests. When writing tests for a new project, however, py.test can be much more convenient.

Now, we will run the doctests from the previously discussed square.py file using py.test.

First, start by ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required