You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support use of skipif/importorskip in conftest.py #4479
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:
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?
@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
@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.
Activity
RonnyPfannschmidt commentedon Nov 29, 2018
extremely unlikely unless someone comes up with a model
drdavella commentedon Nov 29, 2018
@RonnyPfannschmidt I'm not sure what you mean.
Is there a better way of accomplishing this, then?
RonnyPfannschmidt commentedon Nov 29, 2018
@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
drdavella commentedon Nov 29, 2018
@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 likeimportorskip, 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.
RonnyPfannschmidt commentedon Nov 29, 2018
you can use the contest to make pytest ignore all files below if the feature is unavailiable