Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions testtools/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import types
import unittest
from collections.abc import Callable, Iterator
from typing import Protocol, TypeVar, cast
from typing import TypeVar, cast
from unittest.case import SkipTest

T = TypeVar("T")
Expand Down Expand Up @@ -56,6 +56,14 @@
TestResult,
)

# Circular import: fixtures imports gather_details from here, we import
# fixtures, leading to gather_details not being available and fixtures being
# unable to import it.
try:
import fixtures
except ImportError:
fixtures = None # type: ignore


class _UnexpectedSuccess(Exception):
"""An unexpected success was raised.
Expand Down Expand Up @@ -183,22 +191,7 @@ def gather_details(source_dict: DetailsDict, target_dict: DetailsDict) -> None:
target_dict[name] = _copy_content(content_object)


# Circular import: fixtures imports gather_details from here, we import
# fixtures, leading to gather_details not being available and fixtures being
# unable to import it.
try:
import fixtures
except ImportError:
fixtures = None # type: ignore


class UseFixtureProtocol(Protocol):
def setUp(self) -> None: ...
def cleanUp(self) -> None: ...
def getDetails(self) -> DetailsDict: ...


UseFixtureT = TypeVar("UseFixtureT", bound=UseFixtureProtocol)
FixtureT = TypeVar("FixtureT", bound="fixtures.Fixture")


def _mods(i: int, mod: int) -> Iterator[int]:
Expand Down Expand Up @@ -892,7 +885,7 @@ def _run_test_method(self, result: TestResult) -> object:
"""
return self._get_test_method()()

def useFixture(self, fixture: UseFixtureT) -> UseFixtureT:
def useFixture(self, fixture: "FixtureT") -> "FixtureT":
"""Use fixture in a test case.

The fixture will be setUp, and self.addCleanup(fixture.cleanUp) called.
Expand Down