GeezerVison is showing github.com — Unresolved annotations shouldn't throw errors on Python 3.14 · Issue #13549 · pytest-dev/pytest
Unresolved annotations shouldn't throw errors on Python 3.14 #13549
Description
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
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() |
Activity
cdce8p commented on Jun 22, 2025
ContributorAuthor
More actions
Maybe a more common case is actually typing only imports being behind if TYPE_CHECKING guards. This also raises a NameError currently but should work fine on Python 3.14+.
# test.py
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from dependency import X
@pytest.fixture
def some_obj() -> X:
...
def test_func(some_obj) -> None:
assert Trueadded a commit that references this issue
on Jun 22, 2025This issue will close once commit 8ca783c is merged into the 'main' branch.8ca783c added a commit that references this issue
on Jun 22, 2025This issue will close once commit eae6faa is merged into the 'main' branch.eae6faa added a commit that references this issue
on Jun 22, 2025This issue will close once commit 242522a is merged into the 'main' branch.242522a
Metadata
Metadata
Development
No branches or pull requestsIssue actions