[TIP] Why do you use "autouse" fixtures?
Florian Bruhin
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)
https://github.com/The-Compiler/qutebrowser/blob/master/tests/conftest.py#L136-L140
- To monkeypatch something away for all tests in a given module or class
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/utils/test_jinja.py#L33-L51
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/config/test_configtypes.py#L823-L830
- Same, to get deterministic outcomes with randomness involved:
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/browser/webkit/test_mhtml.py#L29-L31
- To save/restore some behaviour the code under test modifies:
https://github.com/The-Compiler/qutebrowser/blob/master/tests/conftest.py#L136-L140
- To set up something all tests need to work (but don't need to access
directly):
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/keyinput/test_basekeyparser.py#L174-L176
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/javascript/position_caret/test_position_caret.py#L29-L36
- To do some kind of cleanup after each test (your first example?):
https://github.com/The-Compiler/qutebrowser/blob/master/tests/unit/misc/test_sessions.py#L54-L57
Florian
--
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
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160726/8e719e8b/attachment.pgp>
More information about the testing-in-python
mailing list