Skip to content

Support use of skipif/importorskip in conftest.py #4479

Closed

Description

@drdavella

I would like to be able to skip tests for an entire submodule of my project based on whether or not an optional dependency is available. Consider the following example package:

myproject/
    setup.py
    myproject/
        foo/
            ...
        bar/
            ...
        baz/
            a/
            b/
            c/

I would like to skip all of the tests found in myproject.baz if my optional dependency is not available. Right now the only way to do that is to put importorskip into each individual test module, OR to write up some custom collection hook, which I don't really want to do.

I could put an importorskip in baz/__init__.py, which actually works. But now I have a runtime dependency on pytest.

Ideally, I would be able to put the importorskip in baz/conftest.py. But this currently doesn't work.

I'm not deeply familiar with the infrastructure here, but is there any chance this could be supported?

Activity

  1. RonnyPfannschmidt commented on Nov 29, 2018

    @RonnyPfannschmidt
    Member

    extremely unlikely unless someone comes up with a model

  2. drdavella commented on Nov 29, 2018

    @drdavella
    Author

    @RonnyPfannschmidt I'm not sure what you mean.

    Is there a better way of accomplishing this, then?

  3. RonnyPfannschmidt commented on Nov 29, 2018

    @RonnyPfannschmidt
    Member

    @drdavella i would suggest a shared module those tests import which does importorskip to sort it ou

    importorskip cant be supported soundly inside of conftest, since conftest is a non-collection part of test-collection - importing conftests should never fail

  4. drdavella commented on Nov 29, 2018

    @drdavella
    Author

    @RonnyPfannschmidt that seems like a pretty good workaround, although still not ideal.

    So maybe I'm asking for the wrong feature here. What I really want is a way, within conftest.py, to say that I don't want to run the tests at or below this level. If it could make use of existing infrastructure like importorskip, that would be cool, but if another mechanism is required, that's fine too.

    Given that, is there any way this could work? Or is this still too hard to support.

  5. RonnyPfannschmidt commented on Nov 29, 2018

    @RonnyPfannschmidt
    Member

    you can use the contest to make pytest ignore all files below if the feature is unavailiable

  6. added
    type: questiongeneral question, might be closed after 2 weeks of inactivity
    on Dec 5, 2018
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

    type: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions