GeezerVison is showing github.com — pytest.skip option to allow to work at module level · Issue #2805 · pytest-dev/pytest
pytest.skip option to allow to work at module level #2805DescriptionAs discussed in #2338
@The-Compiler wrote
The Skipped exception already has allow_module_level=True as argument which is used by pytest.importorskip internally - so you should already be able to do raise pytest.skip.Exception("...", allow_module_level=True).
I think we should just expose that via pytest.skip(...) too. Activitygeorgeyk commented on Oct 1, 2017 @nicoddemus Hi, can I try to fix this ?
I'm not familiar with the codebase, but it looks like the following:
- update
|
def skip(msg=""): |
|
""" skip an executing test with the given message. Note: it's usually |
|
better to use the pytest.mark.skipif marker to declare a test to be |
|
skipped under certain conditions like mismatching platforms or |
|
dependencies. See the pytest_skipping plugin for details. |
|
""" |
|
__tracebackhide__ = True |
|
raise Skipped(msg=msg) |
to add allow_module_level
- and here too:
|
def pytest_runtest_setup(item): |
|
# Check if skip or skipif are specified as pytest marks |
|
|
|
skipif_info = item.keywords.get('skipif') |
|
if isinstance(skipif_info, (MarkInfo, MarkDecorator)): |
|
eval_skipif = MarkEvaluator(item, 'skipif') |
|
if eval_skipif.istrue(): |
|
item._evalskip = eval_skipif |
|
skip(eval_skipif.getexplanation()) |
|
|
|
skip_info = item.keywords.get('skip') |
|
if isinstance(skip_info, (MarkInfo, MarkDecorator)): |
|
item._evalskip = True |
|
if 'reason' in skip_info.kwargs: |
|
skip(skip_info.kwargs['reason']) |
|
elif skip_info.args: |
|
skip(skip_info.args[0]) |
|
else: |
|
skip("unconditional skip") |
|
|
|
item._evalxfail = MarkEvaluator(item, 'xfail') |
|
check_xfail_no_run(item) |
- tests and docs
Is that correct ? nicoddemus commented on Oct 1, 2017 Hi @georgeyk actually it is simpler. 😁
pytest.skip raises Skipped, and that class already supports the flag we want:
|
class Skipped(OutcomeException): |
|
# XXX hackish: on 3k we fake to live in the builtins |
|
# in order to have Skipped exception printing shorter/nicer |
|
__module__ = 'builtins' |
|
|
|
def __init__(self, msg=None, pytrace=True, allow_module_level=False): |
|
OutcomeException.__init__(self, msg=msg, pytrace=pytrace) |
|
self.allow_module_level = allow_module_level |
So it is just a matter of changing pytest.skip to accept a keyword argument allow_module_level and forward that to Skipped.
I would like for allow_module_level to be keyword-argument only, but given that we don't have support for that in Python 2 I would code pytest.skip like this:
def skip(msg="", **kwargs):
""" ...
:kwarg bool allow_module_level: allows this function to be called at the module level, skipping the
rest of the module. Default to False.
"""
__tracebackhide__ = True
allow_module_level = kwargs.pop('allow_module_level', False)
if kwargs:
raise TypeError('unexpected keyword arguments: {}'.format(kwargs.keys())
raise Skipped(msg=msg, allow_module_level=allow_module_level)
And then a test and docs. 👍 Reacted by Oliver Bestwalter and George Kussumoto bilderbuchi commented on Oct 24, 2017 @nicoddemus the related PR for this issue is merged.
I could not find the policy regarding when to close issues, i.e. close when the fix is merged into the repo or when it is released. It probably would make sense to document that in the contributor documents.
IMHO, the former makes more sense, as closed issues are nearly as discoverable as open ones on Github, and it keeps your issues list (i.e. the list of things that still need work) a bit cleaner. RonnyPfannschmidt commented on Oct 24, 2017 thanks for the note - we try to close automatically with merging, but sometimes a reference is forgotten bilderbuchi commented on Oct 24, 2017 nicoddemus commented on Oct 24, 2017 Our policy is to close as soon as the fix is merged either on master or features as you suggest.
What happened is that it was merged to the features branch, and GH will only handle commit commands when they are merged to master. Also sometimes people forget/don't know to add "Fix #X" to the commit message as well and we end up forgetting to close manually. bilderbuchi commented on Oct 24, 2017 OK. I've used the GH API to automatically identify a handful of issues (back until ~ issue 2400) that should be closed, I'll @mention you to close them. Reacted by Ronny Pfannschmidt
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|