move tests into deprecated_test, and test for number of warnings issued

This commit is contained in:
Thomas Grainger 2022-10-10 13:48:26 +01:00
parent a1b10b552a
commit f7542f6292
No known key found for this signature in database
GPG Key ID: DDA48B5C47FBC8C8
2 changed files with 32 additions and 18 deletions

View File

@ -279,3 +279,35 @@ def test_importing_instance_is_deprecated(pytester: Pytester) -> None:
match=re.escape("The pytest.Instance collector type is deprecated"),
):
from _pytest.python import Instance # noqa: F401
def test_fixture_disallow_on_marked_functions():
"""Test that applying @pytest.fixture to a marked function warns (#3364)."""
with pytest.warns(
pytest.PytestDeprecationWarning,
match=r"Marks applied to fixtures have no effect",
) as record:
@pytest.fixture
@pytest.mark.parametrize("example", ["hello"])
@pytest.mark.usefixtures("tmp_path")
def foo():
raise NotImplementedError()
assert len(record) == 1
def test_fixture_disallow_marks_on_fixtures():
"""Test that applying a mark to a fixture warns (#3364)."""
with pytest.warns(
pytest.PytestDeprecationWarning,
match=r"Marks applied to fixtures have no effect",
) as record:
@pytest.mark.parametrize("example", ["hello"])
@pytest.mark.usefixtures("tmp_path")
@pytest.fixture
def foo():
raise NotImplementedError()
assert len(record) == 2

View File

@ -3620,24 +3620,6 @@ class TestShowFixtures:
def foo():
raise NotImplementedError()
def test_fixture_disallow_on_marked_functions(self):
"""Test that applying @pytest.fixture to a marked function warns (#3364)."""
with pytest.warns(pytest.PytestDeprecationWarning):
@pytest.fixture
@pytest.mark.usefixtures("tmp_path")
def foo():
raise NotImplementedError()
def test_fixture_disallow_marks_on_fixtures(self):
"""Test that applying a mark to a fixture warns (#3364)."""
with pytest.warns(pytest.PytestDeprecationWarning):
@pytest.mark.usefixtures("tmp_path")
@pytest.fixture
def foo():
raise NotImplementedError()
class TestContextManagerFixtureFuncs:
def test_simple(self, pytester: Pytester) -> None: