Skip to content

Scopes of several files are merged when specifying a config using -c #9703

Open
@fjarri

Description

@fjarri

Setup:

Python 3.9.9, pip list:

attrs      21.4.0
iniconfig  1.1.1
packaging  21.3
pip        21.3.1
pluggy     1.0.0
py         1.11.0
pyparsing  3.0.7
pytest     7.0.1
setuptools 60.5.0
tomli      2.0.1
wheel      0.37.1

(basically just whatever pip install pytest installs)

Files:

# <dir>/test/test_file1.py

import pytest

@pytest.fixture(autouse=True)
def some_fixture():
    print("Fixture called")

def test_in_file1():
    print("test_in_file1")
# <dir>/test/test_file2.py

def test_in_file2():
    print("test_in_file2")
# <dir>/config/pytest.ini
[pytest]

Running with specifying the config from config explicitly executes the fixture for both tests:
py.test -c config/pytest.ini -s -v tests/test_file1.py tests/test_file2.py

config/::test_in_file1 Fixture called
test_in_file1
PASSED
config/::test_in_file2 Fixture called
test_in_file2
PASSED

Omitting the config, using a config from the root directory <dir>, or not specifying the test files explicitly (just py.test -c config/pytest.ini -s -v):

config/tests/test_file1.py::test_in_file1 Fixture called
test_in_file1
PASSED
config/tests/test_file2.py::test_in_file2 test_in_file2
PASSED

which is the behavior I would expect.

Downgrading to pytest==6.2.5 and running the command above (py.test -c config/pytest.ini -s -v tests/test_file1.py tests/test_file2.py) does not lead to the bug either. Interestingly enough, the "config" prefix is missing from the output:

tests/test_file1.py::test_in_file1 Fixture called
test_in_file1
PASSED
tests/test_file2.py::test_in_file2 test_in_file2
PASSED

Must be some config-based grouping feature introduced in 7?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: criticalgrave problem or usability issue that affects lots of userstopic: collectionrelated to the collection phasetype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions