Somewhat unexpectedly, I attended a tutorial on py.test at EuroPython today — which turned out to be very useful.

Below are my raw (i.e. imperfect and likely inadequate) notes from that session.

  • minimal, no-API approach; no need for boilerplates
    however, a lot of optional framework-y functionality is provided
  • convention over configuration (automatic discovery of test_*.py, def test_*, class Test*)
  • py.test overrides AssertionError built-in, then re-runs statement to provide details — avoid assertions with side-effects!
  • skip tests only for platform and dependency issues; use @py.test.mark.xfail for “expected to fail”
  • funcargs introduced in v1.0 to replace traditional setup methods for fixtures (user & provider, loose coupling); allows for more flexible grouping
  • print captured by default, only shown on failure
  • internally makes use of its own hook architecture (i.e. many features implemented as plugins)
  • yielded tests are deprecated (due to internal ambiguity); recommended to use pytest_generate_tests instead
  • interesting plugins: coverage and PyLint integration
  • can be used to run non-Python tests (e.g. for JavaScript)
  • supports distributed testing (load balancing with multiple CPUs or remote machines, testing on multiple platforms)
  • might be renamed (“I wish I’d named it differently”)

Holger Krekel has also published his slides (PDF), which are well worth a look.