Funcargs & other fun with pytest
-
Upload
brianna-laugher -
Category
Technology
-
view
20.700 -
download
3
description
Transcript of Funcargs & other fun with pytest
PyCon AU 2012Brianna Laugher
funcargs & other fun
with pytest
pytest – all the good stuff✔ all test styles: unittest, doctest, nose✔ boilerplate-free style – natural asserts✔ support for running tests distributed, boxed✔ generate JUnit-style XML for Jenkins CI✔ informative error reporting✔ extensible plugins, useful builtins✔ skip, xfail, custom markers✔ parametrize, generate tests✔ monkeypatch✔ funcargs!
my background
● using pytest seriously for ~18 months at work● really enjoying it!● how it feels to use pytest: →
Graphical Forecast Editor
● client/server desktop application used by forecasters to generate the (text & graphical) forecasts
● pilot in VIC, funding to roll out nationally, ~5 year project, 20+ new devs/testers
● existing codebase of Python and C++ (used operationally in US)● home-grown test suite and runner (via GUI)
informative error reporting
informative error reporting
extensible
● e.g. add in unittest assert methods
extensible
● e.g. add hook for winpdb
skip
xfail
custom markers
parametrize
generate tests● defined once per module● list/generate data to supply to 1+ tests● way more flexible cf. py.test.mark.parametrize
generate generators!
monkeypatch
funcargs!
funcargs – idealised db example
funcargs – trivial django example
funcargs – trivial GAE examples
funcargs – trivial GAE examples
funcargs – why?
● dependency injection, aka inversion of control● works a treat with TDD● very natural with mocking● encourages modular design
funcargs – a real DB example
funcargs – a real DB example
funcargs – to express prereq's
● for when a decorator is not powerful enough
funcargs – to hide monkeypatch :)
generate + funcarg - anypython
pytest – the future
test evolution -v0
test evolution - v1
test evolution - v2
test evolution – v3
test evolution - v4
pytest – all the good stuff✔ all test styles: unittest, doctest, nose✔ boilerplate-free style – natural asserts✔ support for running tests distributed, boxed✔ generate JUnit-style XML for Jenkins CI✔ informative error reporting✔ extensible plugins, useful builtins✔ skip, xfail, custom markers✔ parametrize, generate tests✔ monkeypatch✔ funcargs!
● http://codespeak.net/mailman/listinfo/py-dev● testing-in-python mailing list● Stack Overflow● lead developer Holger Krekel is very
responsive
pytest.org
credits, thanks, contactComic panels from comicallyvintage.tumblr.com
Bureau of Meteorology● In particular, Darius Powell introduced pytest to our
project
Code examples: gist.github.com/3386951
[email protected] / [email protected]
@pfctdayelise