Require future annotations import for tests (I002)

- Applied through ruff `--fix`
- Subsequently simplified optional in `tests/feature/test_report.py`
This commit is contained in:
Kieran Ryan 2024-12-30 01:09:38 +00:00
parent f5eedc981b
commit 06bc96e8ab
37 changed files with 72 additions and 14 deletions

View File

@ -5,6 +5,7 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
from __future__ import annotations
from importlib import metadata as _metadata

View File

@ -73,10 +73,6 @@ lint.isort.required-imports = [
"from __future__ import annotations",
]
[tool.ruff.lint.per-file-ignores]
# Lint `I002` (required imports) for `from __future__ import annotations` in `src/`
"!src/**.py" = ["I002"]
[tool.coverage.report]
exclude_lines = [
"if TYPE_CHECKING:",

View File

@ -1,5 +1,7 @@
"""Step arguments tests."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Step arguments tests."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Step arguments tests."""
from __future__ import annotations
import textwrap

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import pytest
pytest_plugins = "pytester"

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap
from src.pytest_bdd.utils import collect_dumped_objects

View File

@ -1,5 +1,7 @@
"""Test step alias when decorated multiple times."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Test feature background."""
from __future__ import annotations
import textwrap
FEATURE = '''\

View File

@ -1,5 +1,7 @@
"""Test descriptions."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Test feature base dir."""
from __future__ import annotations
import os
import pytest

View File

@ -200,9 +200,7 @@ def test_step_parameters_should_be_replaced_by_their_values(pytester):
Examples:
| start | eat | left |
|{start}|{eat}|{left}|
""".format(
**example
)
""".format(**example)
),
)
pytester.makepyfile(

View File

@ -1,5 +1,7 @@
"""Test no scenarios defined in the feature file."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Scenario Outline tests."""
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects

View File

@ -1,5 +1,7 @@
"""Scenario Outline with empty example values tests."""
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects

View File

@ -1,7 +1,8 @@
"""Test scenario reporting."""
from __future__ import annotations
import textwrap
from typing import Optional
import pytest
@ -11,7 +12,7 @@ from pytest_bdd.reporting import test_report_context_registry
class OfType:
"""Helper object comparison to which is always 'equal'."""
def __init__(self, type: Optional[type] = None) -> None:
def __init__(self, type: type | None = None) -> None:
self.type = type
def __eq__(self, other: object) -> bool:

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Function name same as step name."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Test scenario decorator."""
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects

View File

@ -1,5 +1,7 @@
"""Test scenarios shortcut."""
from __future__ import annotations
import textwrap

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Test tags."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Test wrong feature syntax."""
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Code generation and assertion tests."""
from __future__ import annotations
import itertools
import textwrap

View File

@ -3,6 +3,8 @@
Check the parent givens are collected and overridden in the local conftest.
"""
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap

View File

@ -1,3 +1,5 @@
from __future__ import annotations
from pathlib import Path
from src.pytest_bdd.gherkin_parser import (

View File

@ -1,5 +1,7 @@
"""Test code generation command."""
from __future__ import annotations
import os
import sys
import textwrap

View File

@ -1,5 +1,7 @@
"""Main command."""
from __future__ import annotations
import os
import sys
import textwrap

View File

@ -1,5 +1,7 @@
"""Test code generation command."""
from __future__ import annotations
import os
import sys
import textwrap
@ -31,11 +33,7 @@ def test_migrate(monkeypatch, capsys, pytester):
expected = textwrap.dedent(
"""
migrated: {0}/test_foo.py
skipped: {0}/__init__.py""".format(
str(tests)
)[
1:
]
skipped: {0}/__init__.py""".format(str(tests))[1:]
)
assert out == expected
assert tests.joinpath("test_foo.py").read_text() == textwrap.dedent(

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap
from typing import Any, Callable
from unittest import mock

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap
from src.pytest_bdd.utils import collect_dumped_objects

View File

@ -1,5 +1,7 @@
"""Given tests."""
from __future__ import annotations
import textwrap

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap

View File

@ -1,5 +1,7 @@
"""Tests for testing cases when we have unicode in feature file."""
from __future__ import annotations
import textwrap

View File

@ -1,3 +1,5 @@
from __future__ import annotations
import textwrap
from pytest_bdd.utils import collect_dumped_objects