Skip to content

document how a fixture can depend on another fixture behaviour, but not on its return value #12923

Closed
@kalfa

Description

@kalfa

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions