[TIP] Why do you use "autouse" fixtures?
me at the-compiler.org
Tue Jul 26 13:47:06 PDT 2016
* Brian Okken <variedthoughts at gmail.com> [2016-07-26 12:14:30 -0700]:
> If you use "autouse" fixtures, I'd like to know why.
> Here are a few examples I can think of:
> * Work that needs done before, between, or after each test run that doesn't
> affect the outcome of the test.
> * Maybe we have long running suites and we want to update some
> reporting system whenever a test finishes.
> * The system under test has error logs that need to be interrogated.
> * The tests maybe should check these logs and fail if new errors are
> created. But just in case the test writer forgets, we can check error logs
> and assert if there's something there. This will cause the test to Error.
> Not as strong as a Fail, but better than missing the problem.
> Are there more reasons?
Some other random examples from my testsuite:
- In conftest.py to fail tests on warnings (though I should probably
switch to pytest-warnings with -Werror)
- To monkeypatch something away for all tests in a given module or class
- Same, to get deterministic outcomes with randomness involved:
- To save/restore some behaviour the code under test modifies:
- To set up something all tests need to work (but don't need to access
- To do some kind of cleanup after each test (your first example?):
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 819 bytes
Desc: not available
More information about the testing-in-python