Open QuLogic opened 6 years ago
I also tried specifying should_skip
as a parameter of the tests; then it doesn't get removed, but it still isn't run first.
this is a sife-effect of introducing the definition note to get access to markers in metafunc -now you suddenly no longer get sway with mutating random state
from my pov this is a unplanned api change that we might want to document, but certainly not revert
since you use-case isnt clear
for whole modules you can just do pytestmark = pytest.skip(...)
I'm aware of pytestmark
, but it is not suitable in this case. In fact, that is essentially what we do right now (except using importorskip
and/or skip
based on some conditions, plus setup some other things, which is why I preferred a fixture).
The problem is that importing Qt4 stops importing from Qt5 and vice versa. So if there's a module level importorskip
, then depending on the order the files are loaded, one or the other will always be skipped. And the user cannot choose with -k
because the choice was made during collection. You can see what I am attempting at matplotlib/matplotlib#12163.
in that case i would propose using a opt-in skip at the module level (you can do a full module skip) as a starting point
to see to a good backend structure things might take a bit longer
if you do have backend abstraction, then ideally you use it for tests instead of having one file per backend (that way backend selection cna be done at the test strart)
however such an "pure" concept might simply not fit practical application in the code as it is right now
Looking at this example, I think adding something like this to test_foo.py
:
@pytest.fixture(autouse=True)
def settings(should_skip, settings):
pass
works to tweak the order. Is that something that might be stable?
its not clear to me what fits well as i currently don't have the time to gather all the context needed to read the mathplotlib in a understanding manner
Is that something that might be stable?
Yes, should_skip
will be instantiated before the other settings
in that example. I believe this is stable and we would not change this lightly.
This one is related tto making ffunctiondefinition part of the collection ttree
Follow-up to #2522 then?
Yup
(I added this to the "detangle node structure" project)
In Matplotlib, we have a general autouse fixture that may or may not load a backend (i.e., UI toolkit) that causes a fatal error (if it doesn't exist), depending on test markers. In an effort to avoid that, I tried to add a fixture that skips tests that might use an unavailable backend. Because file-specific fixtures run after those in
conftest.py
, I usedpytest_generate_tests
to implement it, but this no longer seems to work on parametrized tests.For the sake of an example, start with an autouse fixture that always fails in
conftest.py
:then in
test_foo.py
, a fixture that should skip the test, inserted first viapytest_generate_tests
so that it occurs before the above exception:This works for
test_foo
;should_skip
is called first and the remaining fixtures are skipped.If I then add a parametrized test:
all of these call
settings
first instead ofshould_skip
. The printout shows thatshould_skip
is no longer in the list of fixtures either.This used to work in pytest 3.6.3, but fails in 3.7.0. I bisected the issue back to #3629, but I'm not sure exactly if that intended for this behaviour to change.