[TIP] pytest and nose - what's to choose between them?
eric at ionrock.org
Tue Aug 13 09:33:55 PDT 2013
Emily Bache writes:
> 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?
We had a rather large pytest based test suite that I migrated to
nose. While both systems had reasonably similar features the biggest
aspect that pushed me back to pytest was the maturity of its features /
Specifically, nose allows configuring tests by adding setup/teardown in
__init__.py files. This feels very pythonic and seems to work
well. Pytest supports a specific conftest.py file and provides a set of
special functions to help do suite setup. While I liked the __init__.py
model nose used, I found the flexibility difficult to keep
organized. The conftest.py file with its specific function API, ended up
being a better guide for organizing the suite configuration.
As we've continued to use pytest, the fixtures feature is really helpful
in reducing code.
There was some nits with nose as well in our experience. Stdout and
stderr redirection was better in pytest. I assume this was a function of
how we set up logging, so it is possible nose was raising a red flag. I
suspect pytest is just a bit more robust in this aspect. As a personal
preference, I liked pytest's default output better than nose. Obviously
my nits are pretty subjective.
I will say that I never felt I couldn't get nose to do what I needed. It
was just that the opinions pytest prescribes felt like they were helpful
and well thought out. That could be a symptom of it fitting my way of
thinking, so YMMV. The point being, nose is very capable, but pytest was
a better choice for us.
Best of luck!
More information about the testing-in-python