~/talk

Forcing unittest to function

Talkat Python + DS fwdays'24 conference · on Saturday, 2024-04-20· [python, testing]
links:none on file
slides:none on file

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

  1. 0:00Introduction
  2. 1:46Unit test limits
  3. 3:34Method-based test problems
  4. 4:40Adding test function support
  5. 5:01Python introspection
  6. 8:18Test discovery
  7. 12:35Two solutions for functions
  8. 12:57Building test case class
  9. 17:36Dynamic method installation
  10. 18:19Wrapping test functions
  11. 20:25Finalizing test case class
  12. 20:46Using load_tests
  13. 24:46FunctionTestCase refactor
  14. 26:56Choosing load_tests
  15. 27:16Asserts without self
  16. 28:39Summary
  17. 29:44Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.