Funcargs and other fun with pytest

Funcargs and other fun with pytest

Presented at PyCon AU 2012.

81daa523dc7fbbd9c083121d564db86c?s=128

Brianna Laugher

August 18, 2012
Tweet

Transcript

  1. PyCon AU 2012 Brianna Laugher funcargs & other fun with

    pytest
  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. None
  4. my background • using pytest seriously for ~18 months at

    work • really enjoying it! • how it feels to use pytest: →
  5. None
  6. None
  7. None
  8. 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)
  9. None
  10. informative error reporting

  11. informative error reporting

  12. extensible • e.g. add in unittest assert methods

  13. extensible • e.g. add hook for winpdb

  14. None
  15. skip

  16. xfail

  17. custom markers

  18. None
  19. parametrize

  20. None
  21. generate tests • defined once per module • list/generate data

    to supply to 1+ tests • way more flexible cf. py.test.mark.parametrize
  22. generate generators!

  23. None
  24. monkeypatch

  25. None
  26. None
  27. None
  28. None
  29. funcargs!

  30. funcargs – idealised db example

  31. funcargs – trivial django example

  32. funcargs – trivial GAE examples

  33. funcargs – trivial GAE examples

  34. None
  35. funcargs – why? • dependency injection, aka inversion of control

    • works a treat with TDD • very natural with mocking • encourages modular design
  36. None
  37. funcargs – a real DB example

  38. funcargs – a real DB example

  39. funcargs – to express prereq's • for when a decorator

    is not powerful enough
  40. None
  41. funcargs – to hide monkeypatch :)

  42. None
  43. generate + funcarg - anypython

  44. None
  45. None
  46. pytest – the future

  47. None
  48. test evolution -v0

  49. None
  50. test evolution - v1

  51. test evolution - v2

  52. test evolution – v3

  53. test evolution - v4

  54. None
  55. 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!
  56. None
  57. None
  58. • http://codespeak.net/mailman/listinfo/py-dev • testing-in-python mailing list • Stack Overflow •

    lead developer Holger Krekel is very responsive
  59. pytest.org

  60. credits, thanks, contact Comic panels from comicallyvintage.tumblr.com Bureau of Meteorology

    • In particular, Darius Powell introduced pytest to our project Code examples: gist.github.com/3386951 brianna@modernthings.org brianna.laugher.id.au / b.laugher@bom.gov.au @pfctdayelise