GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
#13550
Closed
Unresolved annotations shouldn't throw errors on Python 3.14#13549
#13550
Copy link

Description

@cdce8p
cdce8p
opened on Jun 21, 2025
Issue body actions

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:

pytest/src/_pytest/compat.py

Line 125 in 9f9b7f4

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

Activity

  1. cdce8p commented on Jun 22, 2025

    @cdce8p
    cdce8p
    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 True
  2. nicoddemus
    closed this as completedin #13550on Jun 22, 2025
  3. nicoddemus
    added a commit that references this issue on Jun 22, 2025

    Defer annotation eval on Python 3.14 (#13550)

    This issue will close once commit 8ca783c is merged into the 'main' branch.
    8ca783c
  4. patchback
    added a commit that references this issue on Jun 22, 2025

    Defer annotation eval on Python 3.14 (#13550)

    This issue will close once commit eae6faa is merged into the 'main' branch.
    eae6faa
  5. nicoddemus
    added a commit that references this issue on Jun 22, 2025

    Defer annotation eval on Python 3.14 (#13550) (#13553)

    This issue will close once commit 242522a is merged into the 'main' branch.
    242522a
  6. luketainton
    added a commit that references this issue on Jan 5, 2026

    chore(deps): update dependency pytest to v9 (#305)

    4b75154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.