I’ve got the test code from my unittest fixture syntax and flow reference, and I want to try to run one class, say
TestSkip from unittest, nosetests, and pytest, to compare the the control flow.
Therefore, I need for each framework:
- The option to make it as quiet as possible (-q for all of them)
- The option to turn off output capture (-s works for both pytest and nose, not needed for unittest)
- The way to call an individual class (this is where they all differ.
In unittest fixture syntax and flow reference, I only presented fixture methods and functions that threw no exceptions.
However, in real production code, it is entirely possible for something to go wrong when setting up test fixtures.
This post is simply do demonstrate exactly what happens to the flow of your test code when an exception is thrown in a fixture function.
And, while I’m at it, I may as well demo the normal control flow when a test fails, asserts, or throws an exception.
This post contains examples of how unittest test fixture functions and methods are written, and in what order they run. It may seem like a long post, but it’s mostly code examples and example output.
I want this to be a useful reference for both the syntax and flow of unittest fixtures.
If I missed something, please comment below, and I’ll update the post.
pip is hands down my favorite way to install stuff in Python.
If you need to use it behind a firewall, download Continue reading