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…]

Test First Programming / Test First Development

Occasionally referred to as Test First Development, Test First Programming is a beautiful concept that radically changed the way I approach software development.

The ideas of Test First Programming and Test Driven Development are often muddled together.
However, Test First is powerful enough to stand on it’s own.
I think it’s important to present the concepts separately.

TDD and many other agile practices build on Test First.
This isn’t just about remembering the past.
The lessons learned from Test First are still very important.

[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…]

Delayed assert / multiple failures per test

A test stops execution once it hits a failing assert statement.
That’s kinda the point of an assert statement, though, so that’s not surprising.

However, sometimes it’s useful to continue with the test even with a failing assert.

I’m going to present one method for getting around this restriction, to test multiple things, allow multiple failures per test, and continue execution after a failure.

I’m not really going to describe the code in detail, but I will give the full source so that you can take it and run with it.

[Read more…]