Help us!

Take some time to transcribe PyCon 2014 talks! Click on the "Share" button below the video and then "Subtitle" to get started.

py.test - Rapid Testing with Minimal Effort

Description

py.test I - rapid testing with minimal effort

Presented by Holger Krekel

Want to learn writing tests in Python? This tutorial introduces basic practises using the popular py.test (http://pytest.org) tool. We start with an overview on testing and tools in Python and then discuss and exercise basic idioms in a step-by-step manner. We cover the basic writing, organisation and running of tests and debugging options. In the second part we discuss setup and teardown of test state, usage and configuration of test functions arguments and introduce coverage testing. We will close with time to answer questions and discuss topics from the participants.

Intended Audience

beginner programmers

Perequisites/knowledge: basic knowledge of python programming

Requirements: Laptop with Python 2.4 or greater installed. Pairing welcome. outline

  • why automated testing?
  • Developer oriented automated tests
  • The test tool question
  • py.test basics
  • py.test fundamental features
  • cross-project test tool
  • A Typical Python test layout
  • Another typical test layout
  • Choosing a test layout
  • automatic test discovery
  • mind the init.py files
  • no boilerplate python test code
  • assert introspection
  • asserting expected exceptions
  • print() debugging / output capturing
  • Getting Started, basic usage [0]
  • Failure / Traceback Demo [0]
  • Skipping tests
  • Dynamically skipping tests
  • Marking test functions
  • Marking a test for conditional skip
  • Marking a test as expected to fail
  • Conditional expected to fail
  • Marking / Skipping exercise [0]
  • Applying Marks to classes or modules
  • break
  • warm up: boilerplate test code
  • "myscan" Exercises of this tutorial
  • sketching our "myscan" project
  • Starting Exercise [1]
  • The example Solution [1]
  • The "test setup" and fixture Problem
  • test functions and funcargs
  • How do funcargs work?
  • funcarg factory notes
  • builtin funcargs
  • usage example: per-test temporary directory
  • next step: adding more tests [2]
  • observation on new tmpdir-using tests
  • The mysetup pattern
  • How the mysetup pattern works
  • next step: introducing "mysetup" pattern [3]
  • The new test function using "mysetup"
  • a simple hook: adding a command line opt
  • the py.test config object
  • exercise: implement a new command line option [4]
  • myscan example completed
  • py.test hooks and plugins
  • Installing "global" plugins
  • exercise: use the "figleaf" plugin
  • local plugins: conftest.py
  • a simple config: ignoring directories
  • a simple default option: verbose
  • quick discussion of advanced usages
  • Summary / questions and answers