Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues a warning when a function is not collected as a test case just because it uses @pytest.fixture (#12989) #13051

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dongfangtianyu
Copy link
Contributor

close #12989 .

  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits.
  • Create a new changelog file in the changelog folder

A function is declared as a test case using the convention of the test prefix in its name , or as a fixture using the pytest.fixture decorator.

When both are used simultaneously, it is not possible to have both a test case and a fixture.

So a warning is issued to remind the user: no test case, only a fixture.

Example

import pytest

@pytest.fixture
def test_function():
    pass
(venv) C:\Users\administrator\pytest\demo>pytest
============================= test session starts ==============================
platform win32 -- Python 3.12.0, pytest-8.4.0.dev262+gf160963c4.d20241211, pluggy-1.5.0
rootdir: C:\Users\administrator\pytest\demo
configfile: pytest.ini
plugins: hypothesis-6.111.0, xdist-3.6.1
collected 0 items                                                               

=============================== warnings summary =============================== 
test_aa.py:1
  C:\Users\administrator\pytest\demo\test_aa.py:1: PytestCollectionWarning: ca
nnot collect test function 'test_function',because it used the '@pytest.fixture' than becomes a fixture (from: test_aa.py)
    import warnings

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================== 1 warning in 0.26s ==============================

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 11, 2024
@dongfangtianyu
Copy link
Contributor Author

Probably should add an ini config that allows old projects to ignore this warning?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided (automation) changelog entry is part of PR
Projects
None yet
1 participant