You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am looking at #1014 and related bugs, there are few on the subject.
It is still unclear to me what do to when a fixture uses another fixture, but it does not refer to it in the code.
From 2013 (the older but on the subject I found), when the ticket was raised, things have changed and now we have really strong type checking and linters.
An example of the code which would raise linters concerns is:
@fixture
def bar(monkeypatch):
with monkeypatch() as mp:
mp.setenv('MYVAR', 1):
yield
@fixture
def foo(monkeypatch, bar):
do_something_depening_on_MYVAR()
foo does not know what bar do, and does not care what bar return value is. the code is unaware.
foo depends on the behaviours of bar, but does not refer to it. so any modern linter would raise it as a problem: unused-arguement
This is solved in test cases with usefixtures() which injects them without putting them in the scope fo the test code.
how is it supposed to work with fixtures?
a valid solution to this ticket to me would be:
document it in the fixture page
and/or add a programmatic way to solve the problem, equivalent to usefixtures()
The text was updated successfully, but these errors were encountered:
IMHO the most obvious option is to configure your linter to not complain about unused arguments in your tests/ folder - it looks like e.g. ruff supports per-file-ignores (so does flake8), and per-directory config files.
I already disable it, but with I am becoming slowly against disabling checks, as the number of things to disable grows.
The problem is that it is not a solution, but a workaround for a lack of something else in pytest, hence this bug report (which could become a feature request as well).
Disabling as workaround potentially hides other problems.
It is not a devastating lack, but nevertheless a lack of the ability to describe a dependency that way, and the solution relies on external abilities to cover by the local lack.
either I disable entirely unused args detection, or I have to disable 1:1 each fixture, being very verbose.
I currently use the latter, to minimise hiding other problems, but increasing verbosity and non python code.
pytest.fixture(..., uses_fixtures: list[str], ...) would be an easy (I guess?) solution to the problem, with the same verbosity of the workaround above, but actually solving the problem.
I am looking at #1014 and related bugs, there are few on the subject.
It is still unclear to me what do to when a fixture uses another fixture, but it does not refer to it in the code.
From 2013 (the older but on the subject I found), when the ticket was raised, things have changed and now we have really strong type checking and linters.
An example of the code which would raise linters concerns is:
foo
does not know whatbar
do, and does not care whatbar
return value is. the code is unaware.foo
depends on the behaviours ofbar
, but does not refer to it. so any modern linter would raise it as a problem: unused-arguementThis is solved in test cases with
usefixtures()
which injects them without putting them in the scope fo the test code.how is it supposed to work with fixtures?
a valid solution to this ticket to me would be:
usefixtures()
The text was updated successfully, but these errors were encountered: