Forcing unittest to function
summary
Claims that unittest can accept plain test functions by using Python introspection and shows two concrete implementations: one building test classes dynamically, one using the load_tests hook to register functions as unittest.FunctionTestCase instances. Demonstrates the actual code patterns: dir and getattr/setattr on modules, wrapping with staticmethod, and binding TestCase methods to get asserts. Measures runtime too — about 0.1s vs 8s compared to a leading third‑party framework — and the final solution works.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:46Unit test limits
- 3:34Method-based test problems
- 4:40Adding test function support
- 5:01Python introspection
- 8:18Test discovery
- 12:35Two solutions for functions
- 12:57Building test case class
- 17:36Dynamic method installation
- 18:19Wrapping test functions
- 20:25Finalizing test case class
- 20:46Using load_tests
- 24:46FunctionTestCase refactor
- 26:56Choosing load_tests
- 27:16Asserts without self
- 28:39Summary
- 29:44Q&A
related talks
27mWhy I use py.test and maybe you should too
01h 23mPython Testing Fundamentals
33mUnit Testing with Pytest
32mpytest for unittesters
35mTesting: Choose Your Weapons
41mTesting is Fun in Python!
49mNext generation unit testing using static reflection
44mTesting the untestable - patterns and use cases analysis
