Funcargs & other fun with pytest
Upcoming SlideShare
Loading in...5
×
 

Funcargs & other fun with pytest

on

  • 20,469 views

Video - http://www.youtube.com/watch?v=DTNejE9EraI ...

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.

Statistics

Views

Total Views
20,469
Views on SlideShare
3,528
Embed Views
16,941

Actions

Likes
7
Downloads
20
Comments
0

20 Embeds 16,941

http://seleniumhq.wordpress.com 14836
http://blog.restartr.com 1406
http://feeds.feedburner.com 458
http://v.restartr.com 158
http://blogs.restartr.com 19
http://www.newsblur.com 17
http://translate.googleusercontent.com 8
http://feedspot.com 7
http://restartr.github.io 7
http://webcache.googleusercontent.com 6
http://xianguo.com 5
https://seleniumhq.wordpress.com 4
http://www.google.co.jp 3
http://www.ustart.org 1
http://www.feedspot.com 1
http://www.box.com 1
http://www.google.com&_=1346702844602 HTTP 1
http://131.253.14.98 1
http://getpocket.com 1
http://www.excite-webtl.jp 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Funcargs & other fun with pytest Funcargs & other fun with pytest Presentation Transcript

  • 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✔ 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 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✔ 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.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