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 fixtures nuts and bolts

I’d like to wrap up this recent series of pytest fixture posts by presenting my version of some sort of reference.
Since this post is running a bit long, here are some links to the content buried in here.

[Read more…]

pytest fixtures easy example

In pytest xUnit style fixtures, I presented a problem where:

  • Two tests exist in a test file.
  • One uses a resource.
  • The other doesn’t.
  • Module level fixtures don’t work if you just want to run the one function that doesn’t use the resource.

I then presented class level fixtures as a way to solve the separation problem.

In this post, I’ll use pytest fixtures to solve the same problem.
I’m not going into details of all the goodies you get with pytest fixtures.
I’ll just stick to solving this problem.
[Read more…]