py.test I - rapid testing with minimal effort

This tutorial introduces automated testing for Python using py.test (http://codespeak.net/py/dist/test.html). We begin with a very short overview of testing in Python and where unit testing py.test fit in. The rest of the tutorial is hands on: a short introduction of something new followed by exercises to experiment with it. First is basic usage of py.test and the features which simplify your test writing experience. We walk through the implementation of tests, setup and tear-down of test state, debugging facilities and point out similarities/differences to other test tools. We talk about command line options which save time running and debugging your tests. We then drop briefly into lecture mode and discuss additional features useful in particular circumstances, such as running Javascript tests, testing the format of text documents, or using py.test in a build system. We will close with time to answer questions and discuss topics from the students.

Presenters

Brian Dorsey is a database and Python developer living in Seattle Washington, USA. He mostly writes command line tools, windows services and more recntly simple web apps. He is a long-time user of and occasional contributor to py.test. He is a co-organizer of the Seattle Python Interest Group (www.seapig.org), a member of www.saturdayhouse.org and co-founder of a co-working space in Seattle (www.giraffelabs.com). He also loves lunch and created www.noonhat.com to help feed that addiction. He doesn't like natto or talking about himself in the third person.

Holger Krekel is a co-founder of the PyPy project and participates on many levels. He is the initiator and maintainer of the popular py.test and a few other tools. In 2004 he founded merlinux, a company focusing on PyPy and py.test developments. Holger has spoken at many EuroPython and PyCon confereces and gave well received testing tutorials at EuroPython 2008 and Pycon-UK 2008.

Requirements

None listed.

Class Outline

Motivation / why automated testing? (10 minutes) - what is unit testing and how does it compare to other types of testing - why do automated testing? benefits, etc - existing python testing tools

What you get with py.test (10 minutes) - overview of all the basic benefits - automatic test discovery, simplicity, 'print' debugging (output redirection), function or class, assert introspection, etc - extra benefits, there if you need them, ignore if not - multiple python version, distributed testing, doctests, etc, etc - similarities and differences between nose and py.test

Installation, basic test functions. (30 minutes) - installation - test functions - 20 minute work time

  • Basic setup and working through inevitable setup problems. Some people will finish very quickly - ask them to help others get setup.

Basic usage of py.test (40 minutes) - reinterpretation of asserts - working with failures - debug with print - exceptions - 10 minute work time - exercises - test classes - setup and teardown test state - skipping tests - 10 minute work time - exercises

Break

Options (25 minutes) - --exitfirst - --looponfailing - run large test set until all tests pass - -k to run tests matching name or keyword - --exec to use different Python interpreters - different options to control traceback generation - 10 minute work time - exercises

Branching out (20 minutes) - generative tests - skipping tests - --pdb - 10 minute work time - exercises

Using doctests (25 minutes) - what are doctests - two usage scenarios - docstrings & stand alone files - how they work demo and examples. - 10 minute work time - exercises

Wrapping up and questions (20 minutes) - where to go from here - quesitons and student topics

Diamond

  • White Oak Technologies Inc. - Diamond

Platinum

  • Google - Platinum
  • Sun - Platinum

Gold

  • ESRI - Gold
  • CCP Games - Gold
  • Visual Numerics, Inc. - Gold
  • Microsoft - Gold
  • Slide.com - Gold
  • Walt Disney Animation Studios - Gold

Silver

  • PSC Group - Silver
  • Enthought - Silver
  • Canonical - Silver
  • Imaginary Landscape - Silver
  • Wingware - Silver
  • ITA Software - Silver
  • Accense - Silver
  • Resolver Systems - Silver
  • Leapfrog Online - Silver
  • Emma Email Marketing - Silver
  • ZeOmega - Silver
  • Oracle Technology Network - Silver
  • VMware - Silver
  • Tummy.com - Silver

Vendor I

  • O'Reilly - Vendor I
  • Informit - Pearson Publishing - Vendor I