Coverage.py allows code exclusion from measurement via comments in Python files. Unlike other tools, it uses customizable regular expressions for these exclusions. This regex-based approach has proven surprisingly powerful, enabling flexibility beyond simple comment markers. Lines matching these regexes, along with their multi-line statements and blocks, are excluded from coverage checks. Initially intended for basic pragmas, this system also facilitated pragma-less exclusions, like automatically ignoring all __repr__ methods. The system's power was further amplified by third-party plugins like covdefaults and coverage-conditional-plugin. A significant enhancement allowed regexes to match multi-line patterns, revolutionizing exclusion capabilities. This change enabled features like excluding entire files using a single regex pattern. Another new feature allows excluding code between specific start and end delimiters. However, this regex flexibility has limitations, struggling with cases like string literals containing pragma text. Complex regexes are sometimes needed for specific patterns, yet can still lead to false positives. Despite these limitations, the regex approach offers a good balance of flexibility, power, and practical usability for real-world code.
nedbatchelder.com
nedbatchelder.com
Create attached notes ...
