Writing unit tests in Python: How do I start?

Viewed 259460

I completed my first proper project in Python and now my task is to write tests for it.

Since this is the first time I did a project, this is the first time I would be writing tests for it.

The question is, how do I start? I have absolutely no idea. Can anyone point me to some documentation/ tutorial/ link/ book that I can use to start with writing tests (and I guess unit testing in particular)

Any advice will be welcomed on this topic.

7 Answers

There are, in my opinion, three great Python testing frameworks that are good to check out:

  • unittest - module comes standard with all Python distributions
  • nose - can run unittest tests, and has less boilerplate.
  • pytest - also runs unittest tests, has less boilerplate, better reporting, and lots of cool extra features

To get a good comparison of all of these, read through the introductions to each at Start Here - Python Testing. There are also extended articles on fixtures, and more there.

Related