funcargs &     other fun               with              pytest        PyCon AU 2012       Brianna Laugher
pytest – all the good stuff✔    all test styles: unittest, doctest, nose✔    boilerplate-free style – natural asserts✔    ...
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) ...
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....
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 nat...
funcargs – a real DB example
funcargs – a real DB example
funcargs – to express prereqs●    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✔    ...
●    http://codespeak.net/mailman/listinfo/py-dev●    testing-in-python mailing list●    Stack Overflow●    lead developer...
pytest.org
credits, thanks, contactComic panels from comicallyvintage.tumblr.comBureau of Meteorology●    In particular, Darius Powel...
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Funcargs & other fun with pytest
Upcoming SlideShare
Loading in...5
×

Funcargs & other fun with pytest

21,159

Published on

Video - http://www.youtube.com/watch?v=DTNejE9EraI
Code - https://gist.github.com/3386951

Pytest is a mature and comprehensive testing suite for Python projects, but it can be a little intimidating for newcomers. Where do these mysterious funcargs come from, how do parametrised tests work, and where are my xUnit-style setUp and tearDown methods?

Pytest lives by "convention over configuration" - which is great once you know what the conventions are. This talk will look at real examples of pytest in use, emphasising the features that differentiate it from nose.

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
21,159
On Slideshare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
29
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Funcargs & other fun with pytest

  1. 1. funcargs & other fun with pytest PyCon AU 2012 Brianna Laugher
  2. 2. 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!
  3. 3. my background● using pytest seriously for ~18 months at work● really enjoying it!● how it feels to use pytest: →
  4. 4. 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)
  5. 5. informative error reporting
  6. 6. informative error reporting
  7. 7. extensible● e.g. add in unittest assert methods
  8. 8. extensible● e.g. add hook for winpdb
  9. 9. skip
  10. 10. xfail
  11. 11. custom markers
  12. 12. parametrize
  13. 13. generate tests● defined once per module● list/generate data to supply to 1+ tests● way more flexible cf. py.test.mark.parametrize
  14. 14. generate generators!
  15. 15. monkeypatch
  16. 16. funcargs!
  17. 17. funcargs – idealised db example
  18. 18. funcargs – trivial django example
  19. 19. funcargs – trivial GAE examples
  20. 20. funcargs – trivial GAE examples
  21. 21. funcargs – why?● dependency injection, aka inversion of control ● works a treat with TDD ● very natural with mocking ● encourages modular design
  22. 22. funcargs – a real DB example
  23. 23. funcargs – a real DB example
  24. 24. funcargs – to express prereqs● for when a decorator is not powerful enough
  25. 25. funcargs – to hide monkeypatch :)
  26. 26. generate + funcarg - anypython
  27. 27. pytest – the future
  28. 28. test evolution -v0
  29. 29. test evolution - v1
  30. 30. test evolution - v2
  31. 31. test evolution – v3
  32. 32. test evolution - v4
  33. 33. 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!
  34. 34. ● http://codespeak.net/mailman/listinfo/py-dev● testing-in-python mailing list● Stack Overflow● lead developer Holger Krekel is very responsive
  35. 35. pytest.org
  36. 36. credits, thanks, contactComic panels from comicallyvintage.tumblr.comBureau of Meteorology● In particular, Darius Powell introduced pytest to our projectCode examples: gist.github.com/3386951 brianna@modernthings.org brianna.laugher.id.au / b.laugher@bom.gov.au @pfctdayelise
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×