pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.08k stars 2.68k forks source link

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

Open The-Compiler opened 5 months ago

The-Compiler commented 5 months ago

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:

https://github.com/pytest-dev/pytest/blob/0070151c630b30e38381f1a3a00e263de4665e26/src/_pytest/fixtures.py#L1536-L1539

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?

RonnyPfannschmidt commented 5 months ago

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

JiajunXu2 commented 5 months ago

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

The-Compiler commented 5 months ago

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

andydluna commented 5 months ago

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!