Skip to content

fixture was not found when defined in a test file but discovered twice #6266

@felixonmars

Description

@felixonmars

I have created a minimal case:

$ tree .
.
├── dir1
│   └── dir2 -> ../dir2
└── dir2
    └── test_fixture.py
$ cat dir2/test_fixture.py
import pytest

@pytest.fixture
def i_am_a_fixture():
    return

def test_fixture(i_am_a_fixture):
    pass
$ pytest
======================= test session starts ========================
platform linux -- Python 3.8.0, pytest-4.6.6, py-1.8.0, pluggy-0.13.1
rootdir: /tmp/test
collected 2 items

dir1/dir2/test_fixture.py .                                  [ 50%]
dir2/test_fixture.py E                                       [100%]

============================== ERRORS ==============================
__________________ ERROR at setup of test_fixture __________________
file /tmp/test/dir1/dir2/test_fixture.py, line 9
  def test_fixture(i_am_a_fixture):
E       fixture 'i_am_a_fixture' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/tmp/test/dir1/dir2/test_fixture.py:9
================ 1 passed, 1 error in 0.01 seconds =================

The error is present in latest 5.2.4 version as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectionrelated to the collection phasetopic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions