|
23 | 23 | import types |
24 | 24 | import unittest |
25 | 25 | from collections.abc import Callable, Iterator |
26 | | -from typing import Protocol, TypeVar, cast |
| 26 | +from typing import TypeVar, cast |
27 | 27 | from unittest.case import SkipTest |
28 | 28 |
|
29 | 29 | T = TypeVar("T") |
|
56 | 56 | TestResult, |
57 | 57 | ) |
58 | 58 |
|
| 59 | +# Circular import: fixtures imports gather_details from here, we import |
| 60 | +# fixtures, leading to gather_details not being available and fixtures being |
| 61 | +# unable to import it. |
| 62 | +try: |
| 63 | + import fixtures |
| 64 | +except ImportError: |
| 65 | + fixtures = None # type: ignore |
| 66 | + |
59 | 67 |
|
60 | 68 | class _UnexpectedSuccess(Exception): |
61 | 69 | """An unexpected success was raised. |
@@ -183,22 +191,7 @@ def gather_details(source_dict: DetailsDict, target_dict: DetailsDict) -> None: |
183 | 191 | target_dict[name] = _copy_content(content_object) |
184 | 192 |
|
185 | 193 |
|
186 | | -# Circular import: fixtures imports gather_details from here, we import |
187 | | -# fixtures, leading to gather_details not being available and fixtures being |
188 | | -# unable to import it. |
189 | | -try: |
190 | | - import fixtures |
191 | | -except ImportError: |
192 | | - fixtures = None # type: ignore |
193 | | - |
194 | | - |
195 | | -class UseFixtureProtocol(Protocol): |
196 | | - def setUp(self) -> None: ... |
197 | | - def cleanUp(self) -> None: ... |
198 | | - def getDetails(self) -> DetailsDict: ... |
199 | | - |
200 | | - |
201 | | -UseFixtureT = TypeVar("UseFixtureT", bound=UseFixtureProtocol) |
| 194 | +FixtureT = TypeVar("FixtureT", bound="fixtures.Fixture") |
202 | 195 |
|
203 | 196 |
|
204 | 197 | def _mods(i: int, mod: int) -> Iterator[int]: |
@@ -892,7 +885,7 @@ def _run_test_method(self, result: TestResult) -> object: |
892 | 885 | """ |
893 | 886 | return self._get_test_method()() |
894 | 887 |
|
895 | | - def useFixture(self, fixture: UseFixtureT) -> UseFixtureT: |
| 888 | + def useFixture(self, fixture: "FixtureT") -> "FixtureT": |
896 | 889 | """Use fixture in a test case. |
897 | 890 |
|
898 | 891 | The fixture will be setUp, and self.addCleanup(fixture.cleanUp) called. |
|
0 commit comments