pytest icon indicating copy to clipboard operation
pytest copied to clipboard

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

Open The-Compiler opened this issue 1 year ago • 4 comments

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?

The-Compiler avatar Jun 06 '24 09:06 The-Compiler

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

RonnyPfannschmidt avatar Jun 06 '24 09:06 RonnyPfannschmidt

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

JiajunXu2 avatar Jun 07 '24 19:06 JiajunXu2

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

The-Compiler avatar Jun 07 '24 20:06 The-Compiler

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!

andydluna avatar Jun 08 '24 03:06 andydluna

Heya, saw that #12439 has gotten a lil stale (no update since July). Alright if I take a crack at picking it up this weekend if I got time?

daria-shaw avatar Nov 27 '24 20:11 daria-shaw

@daara-s sure! Please pull the original commits into your branch and add yours on top so that we'd credit that author too.

webknjaz avatar Nov 27 '24 21:11 webknjaz