Python: Bypass Coverage For @overload Methods

In Python, we can use @overload decorator from typing to mark overloading methods. If project has unit test enabled, you may find that it’s impossible to cover those methods with @overload decorator in coverage reports. In this case we have to bypass coverage checking for those overloading methods.

In setup.cfg:

1
2
3
4
[coverage:report]
exclude_lines =
pragma: not covered
@overload

Or in pyproject.toml:

1
2
3
4
[tool.coverage.report]
exclude_lines =
pragma: not covered
@overload