mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-22 21:59:59 +00:00
## Problem `TYPE_CHECKING` is used inconsistently across Python tests. ## Summary of changes - Update `ruff`: 0.7.0 -> 0.11.2 - Enable TC (flake8-type-checking): https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc - (auto)fix all new issues
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import MutableMapping
|
|
from typing import TYPE_CHECKING, cast
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import MutableMapping
|
|
from typing import Any
|
|
|
|
import pytest
|
|
from _pytest.config import Config
|
|
|
|
|
|
def pytest_collection_modifyitems(config: Config, items: list[pytest.Item]):
|
|
# pytest-rerunfailures is not compatible with pytest-timeout (timeout is not set for reruns),
|
|
# we can workaround it by setting `timeout_func_only` to True[1].
|
|
# Unfortunately, setting `timeout_func_only = True` globally in pytest.ini is broken[2],
|
|
# but we still can do it using pytest marker.
|
|
#
|
|
# - [1] https://github.com/pytest-dev/pytest-rerunfailures/issues/99
|
|
# - [2] https://github.com/pytest-dev/pytest-timeout/issues/142
|
|
|
|
if not config.getoption("--reruns"):
|
|
return
|
|
|
|
for item in items:
|
|
timeout_marker = item.get_closest_marker("timeout")
|
|
if timeout_marker is not None:
|
|
kwargs = cast("MutableMapping[str, Any]", timeout_marker.kwargs)
|
|
kwargs["func_only"] = True
|