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.

Improve handling of skip for module level

See original GitHub issue

This is potentially about updating docs, updating error messages or introducing a new API.

Consider the following scenario:

pos_only.py is using Python 3,8 syntax:

def foo(a, /, b):
    return a + b

It should not be tested under Python 3.6 and 3.7. This is a proper way to skip the test in Python older than 3.8:

from pytest import raises, skip
import sys
if sys.version_info < (3, 8):
    skip(msg="Requires Python >= 3.8", allow_module_level=True)

# import must be after the module level skip:
from pos_only import *

def test_foo():
    assert foo(10, 20) == 30
    assert foo(10, b=20) == 30
    with raises(TypeError):
        assert foo(a=10, b=20)

My actual test involves parameterize and a 3.8 only class, so skipping the test itself is not sufficient because the 3.8 class was used in the parameterization.

A naive user will try to initially skip the module like:

if sys.version_info < (3, 8):
    skip(msg="Requires Python >= 3.8")

This issues this error:

Using pytest.skip outside of a test is not allowed. To decorate a test function, use the @pytest.mark.skip or @pytest.mark.skipif decorators instead, and to skip a module use `pytestmark = pytest.mark.{skip,skipif}.

The proposed solution pytestmark = pytest.mark.{skip,skipif}, does not work in my case: pytest continues to process the file and fail when it hits the 3.8 syntax (when running with an older version of Python).

The correct solution, to use skip as a function is actively discouraged by the error message.

This area feels a bit unpolished. A few ideas to improve:

  1. Explain skip with allow_module_level in the error message. this seems in conflict with the spirit of the message.
  2. Create an alternative API to skip a module to make things easier: skip_module("reason"), which can call _skip(msg=msg, allow_module_level=True).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, Apr 25, 2021

I agree it would be healthier, but -1 from me for the same reasons as @The-Compiler: we already had a deprecation/change period in order to introduce allow_module_level, having yet another one is frustrating/confusing to users, in comparison to the small gains.

1reaction
The-Compilercommented, Apr 25, 2021

-0.5 from my side - I think this is too minor to warrant another deprecation and change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyTest: skip entire module/file (python 2 and 3) - Stack Overflow
A more straightforward solution would be to use pytest.importorskip instead.
Read more >
Intuitive Explanation of Skip Connections in Deep Learning
Skip connections for the win​​ At present, skip connection is a standard module in many convolutional architectures. By using a skip connection, ...
Read more >
Skip Connections | All You Need to Know About Skip ...
In this article, we've discussed the importance of skip connections for the training of deep neural nets and how skip connections were used....
Read more >
Skip Logic - Qualtrics
Select the question to which you want to add skip logic. · In the Question behavior section of the survey builder, select Skip...
Read more >
12 Terraform Best Practices to Improve your TF workflow
Learn some best practices that will assist you in pushing your Terraform skills to the next level. See how they can make your...
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