As discussed in pytest-dev/pytest#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.
@nicoddemus Hi, can I try to fix this ?
I'm not familiar with the codebase, but it looks like the following:
allow_module_level Is that correct ?
Hi @georgeyk actually it is simpler. 馃榿
pytest.skip raises Skipped, and that class already supports the flag we want:
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. 馃憤
@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.
thanks for the note - we try to close automatically with merging, but sometimes a reference is forgotten
OK, thanks.
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.
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.
Most helpful comment
Hi @georgeyk actually it is simpler. 馃榿
pytest.skipraisesSkipped, and that class already supports the flag we want:https://github.com/pytest-dev/pytest/blob/6690b8a44420aba860e6f2c79ca296e61e249f3c/_pytest/outcomes.py#L32-L39
So it is just a matter of changing
pytest.skipto accept a keyword argumentallow_module_leveland forward that toSkipped.I would like for
allow_module_levelto be keyword-argument only, but given that we don't have support for that in Python 2 I would codepytest.skiplike this:And then a test and docs. 馃憤