Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion testtools/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import locale
import os
import sys
import typing
import unicodedata

# Ensure retro-compatibility with older testtools releases
from io import BytesIO, StringIO


def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
def reraise(exc_class, exc_obj, exc_tb, _marker=object()) -> typing.NoReturn:
"""Re-raise an exception received from sys.exc_info() or similar."""
raise exc_obj.with_traceback(exc_tb)

Expand Down
12 changes: 11 additions & 1 deletion testtools/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
import types
import unittest
from typing import Any, Protocol, TypeVar
from unittest.case import SkipTest

from testtools import content
Expand Down Expand Up @@ -168,6 +169,15 @@ def gather_details(source_dict, target_dict):
fixtures = try_import("fixtures")


class UseFixtureProtocol(Protocol):
def setUp(self) -> Any: ...
def cleanUp(self) -> Any: ...
def getDetails(self) -> dict[str, content.Content]: ...


UseFixtureT = TypeVar("UseFixtureT", bound=UseFixtureProtocol)


def _mods(i, mod):
(q, r) = divmod(i, mod)
while True:
Expand Down Expand Up @@ -729,7 +739,7 @@ def _run_test_method(self, result):
"""
return self._get_test_method()()

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

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