GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #2805

New issue
Copy link
New issue
Copy link
Closed
Closed
pytest.skip option to allow to work at module level#2805
Copy link
Labels
good first issueeasy issue that is friendly to new contributortopic: selectionrelated to test selection from the command linetype: enhancementnew feature or API change, should be merged into features branch

Description

@nicoddemus
nicoddemus
opened on Sep 28, 2017
Issue body actions

As 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.

Activity

  1. nicoddemus
    added
    Hacktoberfest
    good first issueeasy issue that is friendly to new contributor
    topic: selectionrelated to test selection from the command line
    type: enhancementnew feature or API change, should be merged into features branch
    on Sep 28, 2017
  2. georgeyk commented on Oct 1, 2017

    @georgeyk
    georgeyk
    on Oct 1, 2017
    Contributor
    More actions

    @nicoddemus Hi, can I try to fix this ?

    I'm not familiar with the codebase, but it looks like the following:

    • update

      pytest/_pytest/outcomes.py

      Lines 65 to 72 in 0a15edd

      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:

      pytest/_pytest/skipping.py

      Lines 156 to 177 in 0a15edd

      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 ?

  3. nicoddemus commented on Oct 1, 2017

    @nicoddemus
    nicoddemus
    on Oct 1, 2017
    MemberAuthor
    More actions

    Hi @georgeyk actually it is simpler. 😁

    pytest.skip raises Skipped, and that class already supports the flag we want:

    pytest/_pytest/outcomes.py

    Lines 32 to 39 in 6690b8a

    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
  4. bilderbuchi commented on Oct 24, 2017

    @bilderbuchi
    bilderbuchi
    on Oct 24, 2017
    Contributor
    More actions

    @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.

  5. RonnyPfannschmidt commented on Oct 24, 2017

    @RonnyPfannschmidt
    RonnyPfannschmidt
    on Oct 24, 2017
    Member
    More actions

    thanks for the note - we try to close automatically with merging, but sometimes a reference is forgotten

  6. RonnyPfannschmidt
    closed this as completedon Oct 24, 2017
  7. bilderbuchi commented on Oct 24, 2017

    @bilderbuchi
    bilderbuchi
    on Oct 24, 2017
    Contributor
    More actions

    OK, thanks.

  8. nicoddemus commented on Oct 24, 2017

    @nicoddemus
    nicoddemus
    on Oct 24, 2017
    MemberAuthor
    More actions

    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.

  9. bilderbuchi commented on Oct 24, 2017

    @bilderbuchi
    bilderbuchi
    on Oct 24, 2017
    Contributor
    More actions

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: selectionrelated to test selection from the command linetype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.