Testing 101 with py.test

Praveen Shirali (~praveen2)


10

Votes

Description:

A workshop on testing python code using the py.test framework.

I plan to cover the following aspects:

  1. Overview of basic tools in python & some packages which a python developer must be aware of: pdb, unittest, mock, coverage, virtualenv etc. [10 min]
  2. Why py.test? What problems does it aim to solve? [5 min]
  3. Hands-on: writing tests for success and failure. Asserting results and handling exceptions. [20 min]
  4. Mocking: How to mock. Where to patch. What to assert on. When not to mock. How to refactor code to make it testable. Monkey-patching & dependency-injection [20 min]
  5. py.test fixtures: How to modularize setup and teardown. Usage of: finalizers, fixture scopes, autouse fixtures etc. [20 min]
  6. conftest.py: How to segregate fixtures into conftest. Usage of py.test hooks and assertion helpers [10 min]
  7. Managing test data and execution: parametrization, marking tests, skipping tests etc [10 min]
  8. Testing test-code/framework code. Utilizing pdb to debug tests. Using coverage as a tool identify areas that need to be tested. [15 min]
  9. An overview of other advanced features of py.test -- plugins, tox, etc. [10 min]

Points 3-8 will be hands-on. Code examples will cover unittests and functional tests (ReST API tests against a web-server).

This workshop is for you if:

  1. You are a developer who has written some test code, but you are keen to more info on py.test and testing in general.
  2. You are a developer who has never written any test code before. You are new to concepts of mocking, patching, dependency-injection, refactoring code for testability etc. You are looking for a place to start.
  3. You are a QA Engineer who uses python for automation and you'd like to see how py.test could help you write tests.

Prerequisites:

  1. You must know variable scopes, modules and packages in python. You must be comfortable with magic methods and reflection.
  2. You must be able to write object-oriented code in Python.
  3. You must be comfortable inspecting objects. Given an object, you know how to identify attributes, bound methods, type, instance checking, mro, etc.
  4. You must know decorators.

Speaker Info:

I am a Test Architect at RiptideIO (http://www.riptideio.com) with around 12+ years of QA experience. I have been using Python for the last 5+ years and py.test for a little over a year. Over the last one year I have been involved in designing and developing test solutions, frameworks and test cases to test our company's products; all of which utilize py.test as the underlying test framework. In the past, I have worked on BDD and functional frameworks (like RobotFramework).

I gave a lightning talk on py.test in PyCon India 2014.

Section: Testing
Type: Workshops
Target Audience: Intermediate
Last Updated:

No comments added so far.

Login to add a new comment.