Skip to content

Fixtures not overriden in directories with similar names #2948

@linards-kalvans

Description

@linards-kalvans

When fixtures with the same name are defined in neighboring directories with similar names (e.g. aaa and aaa1 as in example below) fixture from only one of the directories is invoked.

I have repeated this with pytest-2.7 and pytest-3.2 on with both python2 and python3 on various Linux OSs.

Consider the following directory/file tree:
pytest
├── aaa
│   ├── conftest.py
│   └── test_fixa.py
├── aaa1
│   ├── conftest.py
│   └── test_fix1.py
├── aaa2
│   ├── conftest.py
│   └── test_fix.py
└── aaaa
├── conftest.py
└── test_fixaa.py

Each conftest.py defines fixture fix, as

import pytest
import os
dir_path = os.path.dirname(os.path.realpath(__file__))

@pytest.fixture()
def fix():
        print (dir_path)

and tests defined as

def test_fix(fix):
        assert 1

When the tests are run the following output is generated:

$ pytest -vs .
========================================================================== test session starts ==========================================================================
platform linux2 -- Python 2.7.13, pytest-3.2.3, py-1.4.34, pluggy-0.4.0 -- /usr/bin/python2
cachedir: .cache
rootdir: /home/linards/tests/python, inifile:
collected 4 items

pytest/aaa/test_fixa.py::test_2 /home/***/tests/python/pytest/aaa
PASSED
pytest/aaa1/test_fix1.py::test_2 /home/***/tests/python/pytest/aaa
PASSED
pytest/aaa2/test_fix.py::test_2 /home/***/tests/python/pytest/aaa
PASSED
pytest/aaaa/test_fixaa.py::test_2 /home/***/tests/python/pytest/aaaa
PASSED

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions