This post has several examples, and covers fixtures, test discovery, asserts, running options, and running unittests and doctests.
Nose’s tagline is “nose extends unittest to make testing easier”.
It’s is a fairly well known python unit test framework, and can run doctests, unittests, and “no boilerplate” tests.
I think of pytest as the run-anything, no boilerplate, no required api, use-this-unless-you-have-a-reason-not-to test framework.
This is really where testing gets fun.
As with previous intro’s on this site, I’ll run through an overview, then a simple example, then throw pytest at my markdown.py project. I’ll also cover fixtures, test discovery, and running unittests with pytest.
I have a confession to make.
I still use Perl. Regularly. But mostly as a command line tool. Is that a reason? or an excuse?
When I started using Python regularly, I tried to replace my Perl usage.
Nothing against Perl, I just wanted to force myself to use Python to aid in my learning of the language.
I still have quite a few Perl habits that are hard to break.
The trouble is that some things are just so darn easy in Perl (if you’ve already learned it), and not so easy (as far as I know) in Python.
The unittest test framework is python’s xUnit style framework.
It is a standard module that you already have if you’ve got python version 2.1 or greater.
In this post, I’ll cover the basics of how to create and run a simple test using unittest.
Then I’ll show how I’m using it to test markdown.py.