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

pytest.mark.usefixtures() without argument gets silently ignored #12426

Open
The-Compiler opened this issue Jun 6, 2024 · 4 comments · May be fixed by #12439
Open

pytest.mark.usefixtures() without argument gets silently ignored #12426

The-Compiler opened this issue Jun 6, 2024 · 4 comments · May be fixed by #12439
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly

Comments

@The-Compiler
Copy link
Member

Someone in my pytest training accidentally did:

import pytest

@pytest.mark.usefixtures()
def test_fixt():
    pass

but forgot to pass a fixture name. Because we do:

pytest/src/_pytest/fixtures.py

Lines 1536 to 1539 in 0070151

def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]:
"""Return the names of usefixtures fixtures applicable to node."""
for mark in node.iter_markers(name="usefixtures"):
yield from mark.args

That results in the mark being silently ignored. IMHO, this should result in a warning or even error instead.

I think this would be a great beginner issue for someone that never contributed to pytest before. Maybe someone at the upcoming sprint wants to take a look?

@The-Compiler The-Compiler added good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly labels Jun 6, 2024
@RonnyPfannschmidt
Copy link
Member

We should start to warn and consider turning it into a error next major release

@JiajunXu2
Copy link

I am currently working on this issue, would it be better to issue a warning or raise an error?

@The-Compiler
Copy link
Member Author

I agree with what Ronny has said above, let's start with a warning

@andydluna
Copy link

Hello. I would love to contribute, but I am not sure how to do so. However, my idea is that we can use the already imported warning module and warn the user whenever node.iter_markers(name="usefixtures") is empty. Hopefully someone can implement it and give it a try!

@JiajunXu2 JiajunXu2 linked a pull request Jun 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: fixtures anything involving fixtures directly or indirectly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants