Testing, debugging, and profiling


This lesson covers testing, debugging and optimization of Python code. If you have basic knowledge of Python and numpy (mostly used for illustrating examples), then you are ready to go.

If you have already written a test suite, used a symbolic debugger and profiled your Python code to find performance bottlenecks, then this lesson is probably too basic for you.

Getting ready

This lesson is based on Python 3, numpy, and ipython (or the jupyter notebook) and introduces a few tools: pytest, line_profiler, and snakeviz (all included in a standard installation of Anaconda).

Material: Example files (zip)


  1. Introduction

Part 1: Testing

  1. Exceptions
  2. Assertions
  3. Unit tests
  4. Running tests with pytest
  5. Summary

Part 2: Debugging

  1. Introduction
  2. Post-mortem debugging
  3. Step-by-step debugging

Part 3: Profiling

  1. Introduction
  2. Total runtime measurements
  3. Detailed runtime measurements