Raphael Pierzina wrote a cool article about how to run use a hook function to only run tests that use a particular fixture. However, I wanted to make it more generic so I could pass in the fixture via command line option. Minor tweak to add options.
I’m especially excited about it because I have two articles featured.
I mostly know Michael from the many years of reading Dr Dobb’s.
And I respect Pragmatic Bookshelf for their work in technical publishing.
So I was thrilled to be asked to contribute.
From the Contents page:
The test of the seriousness of any programming project is the seriousness of its testing.
This month Brian Okken takes us on a tour of testing in Python with two articles.
First he works through some of the factors you need to weigh in choosing a test framework for Python.
Then he shows the advantages of one approach to testing in Python, drawn from Behavior-Driven Development.
There looks like lots of other great articles in there too.
I’ve made a few changes to the pytest-expect fixture plugin.
- I’ve put the plugin code on github, https://github.com/okken/pytest-expect.
- It is re-arranged to be a plugin installable with pip. Although I don’t have it in pypi yet.
- I’ve modified the code to use pytest 2.7.0 @pytest.mark.hookwrapper.
- I incorporated Bruno’s feedback from the last post to allow both assert failures and expect failures to be reported in the same test.
- 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:
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.
- 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.
- 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.
- 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.