|
23 | 23 | from fixtures.fixture import Fixture |
24 | 24 | import fixtures.fixture |
25 | 25 |
|
26 | | -gather_details = fixtures.fixture.gather_details # type: ignore[attr-defined] |
| 26 | +gather_details = fixtures.fixture.gather_details |
27 | 27 |
|
28 | 28 | T = TypeVar("T", bound=Fixture) |
29 | 29 |
|
@@ -52,15 +52,23 @@ def useFixture(self, fixture: T) -> T: |
52 | 52 | try: |
53 | 53 | fixture.setUp() |
54 | 54 | except: |
55 | | - if use_details: |
| 55 | + if gather_details is not None and use_details: |
56 | 56 | # Capture the details now, in case the fixture goes away. |
57 | | - gather_details(fixture.getDetails(), self.getDetails()) # type: ignore[attr-defined] |
| 57 | + get_details = getattr(self, "getDetails", None) |
| 58 | + if get_details is not None: |
| 59 | + gather_details(fixture.getDetails(), get_details()) |
58 | 60 | raise |
59 | 61 | else: |
60 | 62 | self.addCleanup(fixture.cleanUp) |
61 | | - if use_details: |
| 63 | + if gather_details is not None and use_details: |
62 | 64 | # Capture the details from the fixture during test teardown; |
63 | 65 | # this will evaluate the details before tearing down the |
64 | 66 | # fixture. |
65 | | - self.addCleanup(gather_details, fixture, self) |
| 67 | + def cleanup_details() -> None: |
| 68 | + if gather_details is not None: |
| 69 | + get_details = getattr(self, "getDetails", None) |
| 70 | + if get_details is not None: |
| 71 | + gather_details(fixture.getDetails(), get_details()) |
| 72 | + |
| 73 | + self.addCleanup(cleanup_details) |
66 | 74 | return fixture |
0 commit comments