April 16, 2022

getattr() Considered Harmful

While Hynek already considered “Considered Harmful” was getting old in 2016, and so he named this blog post hasattr() – A Dangerous Misnomer, instead of hasattr() considered harmful, meanwhile it is 2022 and I still like that phrase. So here we go… getattr() considered harmful The setting is a CLI application with 100% test coverage, and even branch coverage is activated. coverage 101 I assume you know what coverage is. 100% test coverage means that the test suite covers all lines of code of your library or application....

November 21, 2021

Combine Coverage for Different Python Versions

Is it enough to run code coverage for a single Python version? Probably, but not necessarily. Especially when you still need to support Python 2.7 (sigh), there could be quite some different code paths for Python 2 and Python 3. A simple example… try: import Queue # Python 2 except ImportError: import queue as Queue # Python 3 But also the different Python 3 versions may require that you not only test your code for each interpreter, but also you need to assess code coverage for the different versions, and certainly you want to make sure you got all paths covered....