`# pragma: no cover` but specific to particular Python version
See original GitHub issueOriginally reported by Tim Tisdall (Bitbucket: tisdall, GitHub: tisdall)
This is related to: https://github.com/Pylons/colander/issues/226
try:
functools.update_wrapper(self, wrapped)
except AttributeError: #non-function
self.__doc__ = getattr(wrapped, '__doc__', None)
There seems to be cases where you need to write code to cover cases in certain versions of Python that are then inaccessible in other versions. In the above example there’s code to handle an exception that occurs in py2, but never happens in py3 (in this situation). It’d be nice to selectively exclude coverage for only certain versions of Python but include it in the versions it’s necessary for.
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
is there a python-version specific "#pragma nocover" available ...
The .coveragerc file will expand environment variables, so you can do: [report] exclude_lines = pragma: no cover pragma: ...
Read more >platform specific configuration · Issue #563 · nedbat/coveragepy
If a block has two platform/OS-specific branches, currently the only way to reach 100% with a single configuration is to use #pragma: no...
Read more >Better unittest coverage stats: excluding code that only ...
We do want to test for coverage of the branch but only when we're running on the correct Python version. Luckily, the matched...
Read more >Platform Dependent Python Coverage Test with Tox
These lines mean that coverage.py should ignore a line if pragma: no cover {platform} is present. Back to tox.ini , include the following...
Read more >_gnupg.py - Apple Open Source
Renamed to gnupg.py to avoid confusion with the previous versions. ... __name__ == 'ntpath': # pragma: no cover # On Windows, we don't...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s a new coverage plugin that can do these sorts of conditionals: https://sobolevn.me/2020/02/conditional-coverage /cc @warsaw @tisdall
You already have all the control you need to create a system like this yourself. The pragma is simply the default for the [report]exclude_lines option in your .coveragerc file. If you like, you can create two config files, one for py2 and another for py3, and specify different pragma syntaxes in each.