[TIP] pytest and nose - what's to choose between them?

Barry Warsaw barry at python.org
Tue Aug 13 11:07:11 PDT 2013


On Aug 13, 2013, at 03:28 PM, Emily Bache wrote:

>I've been looking at pytest and nose as alternatives to unittest, since
>they both offer a pythonic interface for writing unit tests without too
>much boilerplate. I was hoping for some opinions from this list about when
>to choose nose and when to choose pytest? What are the main advantages of
>each? My target python version is 3.3, does that make a difference?

I haven't really looked much at pytest, but I'm in the process of migrating a
couple of codebases to nose (one from zc.testing and another from straight-up
unittest).  There are a lot of things I like about nose, but some things I've
been struggling with a bit.

For example, I can't really use the doctest plugin because of

https://github.com/nose-devs/nose/issues/594

I can work around it for the most part by using the rich plugin API.  I
basically create my own doctest instances that have the fixtures I want.

I've had some problems with getting plugins to actually be registered,
enabled, and used.  It seems that if the plugin provides command line options
that conflict with other (i.e. built-in) plugins, the entire plugin is
disabled.  It's not obvious when this happens.

On the positive side, I've had to change almost nothing about the structure of
my existing tests to migrate to nose.  My existing fixtures mostly work,
although I did have to do some reorganization to work around the assumptions
imposed by zc.testing's layer arrangement.  Instead of using layers, I now use
a base class.

One thing I really like about nose is the ability to write a plugin that
executes some code before the tests begin.  I had an ugly hack to do this in
zc.testing/zc.buildout but now I just add a begin() method to my plugin and it
does all the pre-initialization I need.

-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130813/2afac6ce/attachment.pgp>


More information about the testing-in-python mailing list