From f7542f629232633b8c9bfeee5c14de19e1070d7f Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 10 Oct 2022 13:48:26 +0100 Subject: [PATCH] move tests into deprecated_test, and test for number of warnings issued --- testing/deprecated_test.py | 32 ++++++++++++++++++++++++++++++++ testing/python/fixtures.py | 18 ------------------ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index d468b4435..01b91ce6d 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -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 diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 4f53ffddc..3ce5cb34d 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -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: