Files
Ilia Zakoulov a73bbf2a4d PY-71370: Resolve any suitable fixture candidate if pytest_plugins cannot be parsed
This bug was introduced during a refactoring of fixture support.
While the correct order of resolution was maintained, it relied on the assumption that pytest_plugins could be statically analyzed.

Consider the following example:
```python
import os
from glob import iglob

DIR_PATH = os.path.dirname(os.path.abspath(__file__))

def create_pytest_plugins():
    # Dynamically resolves fixture plugin names by scanning the fixtures directory
    fixture_names = _make_fixture_names("tests/utils/fixtures/**/*.py")
    return fixture_names

def _make_fixture_names(fixture_path_pattern: str):
    os.chdir(f"{DIR_PATH}/../../")
    return [
        _make_fixture_name(fixture_path)
        for fixture_path in iglob(fixture_path_pattern, recursive=True)
        if "__" not in fixture_path
    ]

def _make_fixture_name(fixture_path: str) -> str:
    return fixture_path.replace("/", ".").replace(".py", "")

pytest_plugins = create_pytest_plugins()
```
In such cases, where pytest_plugins is resolved dynamically and cannot be parsed statically, it is preferable to fall back to resolving any other suitable fixture found in the project, rather than skipping resolution altogether.


(cherry picked from commit 2d9a5dd6bd34d1c06d47b3587cd365696642ccd7)

IJ-MR-167570

GitOrigin-RevId: 709f080d6c23d1f76ad397cb6363e74623758cfd
2025-07-01 15:11:20 +00:00

10 lines
313 B
Python

def calculate_fixtures():
# Imitate custom logic around collecting folders.
# For the real-world examples see PY-71370
fixtures_folder = "fixtures"
subdirectories = ["first", "second"]
return [f"{fixtures_folder}.{subdir}" for subdir in subdirectories]
pytest_plugins = calculate_fixtures()