Pro tips for writing great unit tests

There is an art to condensing test concepts into readable, fast, clear predicates.

  • We look at many examples and show how they can be improve
  • Master the use of any() and all() with generator expressions.
  • Expression set() relations to express big ideas clearly.
  • Cover the problem space with combinatoric iterators: product(), combinations(), permutations()
  • Use subtests for clear error reporting
  • Factor-out data acquisition and parsing from the test predicates.
  • Learn patterns for testing edge cases.
  • Cover class based technique for test reuse.
  • Make effective use of setup and teardown.
  • We look at many examples and show how they can be improved
  • Treating TDD test cases and bug test cases with special reverence.
Raymond Hettinger
Python & Friends
Speaker photo

Raymond Hettinger

he / him

Raymond is a distinguished contributor to the Python core. He created sets, generator expressions, the collections and itertools modules, and designed the compact-and-ordered dict.

      Powered by Vercel Logo