question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`# pragma: no cover` but specific to particular Python version

See original GitHub issue

Originally 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:closed
  • Created 8 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
nedbatcommented, Feb 25, 2020

There’s a new coverage plugin that can do these sorts of conditionals: https://sobolevn.me/2020/02/conditional-coverage /cc @warsaw @tisdall

0reactions
nedbatcommented, Jun 23, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found