@pytest.mark.*
priority seems odd
#10391
-
Suppose I have a test class for which I want to turn warnings into errors. However, some of the parametrizations I'm going to test will emit warnings and I just want to ignore them. I thought, I can write something like import pytest
import warnings
@pytest.mark.filterwarnings("error")
class TestMarkClass:
@pytest.mark.parametrize("_", [pytest.param(None, marks=pytest.mark.filterwarnings("ignore"))])
def test_foo(self, _):
warnings.warn("foo") However, it seems that the class wide mark takes priority over the one in the parametrization. On the flip side, if I mark the individual tests like class TestMarkMethods:
@pytest.mark.filterwarnings("error")
@pytest.mark.parametrize("_", [pytest.param(None, marks=pytest.mark.filterwarnings("ignore"))])
def test_bar(self, _):
warnings.warn("bar")
@pytest.mark.parametrize("_", [pytest.param(None, marks=pytest.mark.filterwarnings("ignore"))])
@pytest.mark.filterwarnings("error")
def test_baz(self, _):
warnings.warn("baz") the mark in the parametrization takes priority. Running everything together with
Is this intentional behavior? I couldn't find anything about the priority order in the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
this is a bug in mark application due to parametrization and collection being muddled this would resolve with the introduction of FunctionDefinition, which is currently blocked by a few other refactorings missing |
Beta Was this translation helpful? Give feedback.
this is a bug in mark application due to parametrization and collection being muddled
this would resolve with the introduction of FunctionDefinition, which is currently blocked by a few other refactorings missing
so a workaround may be necessity, which is also a "breaking change"