Pytest vs Unittest vs Nose (PT002)

Choosing a test framework

Subscribe in iTunes

I list my requirements for a framework and discuss how Pytest, Unittest, and Nose measure up to those requirements.


I did the audio processing differently for this episode. Please let me know how it sounds, if there are any problems, etc.

pytest-expect code now in a github repo

I’ve made a few changes to the pytest-expect fixture plugin.

  1. I’ve put the plugin code on github,
  2. It is re-arranged to be a plugin installable with pip. Although I don’t have it in pypi yet.
  3. I’ve modified the code to use pytest 2.7.0 @pytest.mark.hookwrapper.
  4. I incorporated Bruno’s feedback from the last post to allow both assert failures and expect failures to be reported in the same test.
  5. There’s a tests directory to test the plugin.

There’s still lots to do. But this is a decent start.

Instead of listing any code here, go check out the pytest-expect repository on github

Also, I’ve set up a pytest-expect page. Not much there yet, but I plan on hosting the documentation for this thing there.

Previous posts in this series:

pytest expect fixture plugin, iteration 1

This is the first iteration that implements ‘expect’ as a fixture.

This is really the third attempt at an ‘expect()’ implementation that allows multiple failures per test.

  1. First attempt was a general solution that works with any test framework, but with a slightly clunky API. The main problem with it was that it required the test to call a final ‘assert_expectations()’ from the test code. If you forgot to call that function, the failures weren’t reported.
  2. Second attempt was a pytest plugin implementation that eliminated the need for the ‘assert_expectations()’ call in the test because it was called automatically. I wasn’t thrilled with this solution. But it works.
  3. In the solution I’m presenting in this post, I’m moving all of the code into one file and implementing ‘expect’ as a pytest fixture.

[Read more…]

pytest delayed assert / multiple failure plugin, iteration 1

In Delayed assert / multiple failures per test, I presented a first attempt at writing an ‘expect()’ function that will allow
a test function to collect multiple failures and not stop execution until the end of the test.

There’s one big thing about that method that I don’t like.
I don’t like having to call ‘assert_expectations()’ within the test.
It would be cool to push that part into a plugin.

So, even though this isn’t the prettiest code, here’s a first attempt at making this a plugin.

[Read more…]