From 95203cb01259a32945c204ef6e8aed01c51eeac6 Mon Sep 17 00:00:00 2001 From: dongfangtianyu <7629022+dongfangtianyu@users.noreply.github.com> Date: Wed, 11 Dec 2024 20:22:37 +0800 Subject: [PATCH] test: ignore the warnings about `becoming a fixture` via config. --- changelog/12989.improvement.rst | 9 ++++++++- pyproject.toml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog/12989.improvement.rst b/changelog/12989.improvement.rst index 41e0ac4f51..6e50bfb0ee 100644 --- a/changelog/12989.improvement.rst +++ b/changelog/12989.improvement.rst @@ -1 +1,8 @@ -Issues a warning when a function is not collected as a test case just because it uses :py:func:`@pytest.fixture` +Issues a warning when a function is not collected as a test case just because it uses :py:func:`@pytest.fixture`. +This helps beginners distinguish fixtures from tests; experienced users can ignore the warning via config. + +.. code-block:: ini + + [pytest] + filterwarnings = + ignore:.*becomes a fixture.*:pytest.PytestCollectionWarning diff --git a/pyproject.toml b/pyproject.toml index dce6a0870e..34f831ed05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -403,6 +403,7 @@ filterwarnings = [ "ignore:VendorImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning", # https://github.com/pytest-dev/execnet/pull/127 "ignore:isSet\\(\\) is deprecated, use is_set\\(\\) instead:DeprecationWarning", + "ignore:.*becomes a fixture.*:pytest.PytestCollectionWarning", ] pytester_example_dir = "testing/example_scripts" markers = [