Skip to content

Unresolved annotations shouldn't throw errors on Python 3.14 #13549

Closed
@cdce8p

Description

@cdce8p

Especially during testing of a new release, I often comment out dependencies and add collect_ignore_glob = ["test_*.py"] to conftest to skip test collection for a whole block for tests which depend on in incompatible dependency. With Python 3.14 the evaluation of annotations is deferred by default, so pytest shouldn't throw an error if a name is undefined. A similar result could previously be archived by adding from __future__ import annotations.

# test.py
import pytest

# from incompatible_dependency import X


@pytest.fixture
def some_obj() -> X:
    ...


def test_func(some_obj) -> None:
    assert True
pytest test.py
test.py:8: in __annotate__
    def some_obj() -> X:
                      ^
E   NameError: name 'X' is not defined

As far as I'm aware, pytest doesn't care about annotations. A possible solution would be to add a compatibility layer to the inspect.signature call with annotation_format=Format.STRING as added argument. In particular here:

parameters = signature(function).parameters.values()

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