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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ classifiers = [
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Testing",
"Typing :: Typed",
]
dynamic = ["version"]
requires-python = ">=3.10"
Expand Down
21 changes: 14 additions & 7 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 Any, Protocol, TypeVar, cast
from typing import Protocol, TypeVar, cast
from unittest.case import SkipTest

T = TypeVar("T")
Expand Down Expand Up @@ -271,9 +271,9 @@ def __init__(self, *args: object, **kwargs: object) -> None:
test_method = self._get_test_method()
if runTest is None:
runTest = getattr(test_method, "_run_test_with", self.run_tests_with)
self.__RunTest: type[RunTest] | Callable[..., RunTest] = cast(
"type[RunTest] | Callable[..., RunTest]", runTest
)
# runTest should be a RunTest class or factory function
assert callable(runTest), f"runTest must be callable, got {type(runTest)}"
self.__RunTest: type[RunTest] | Callable[..., RunTest] = runTest
if getattr(test_method, "__unittest_expecting_failure__", False):
setattr(self, self._testMethodName, _expectedFailure(test_method))
# Used internally for onException processing - used to gather extra
Expand Down Expand Up @@ -1130,16 +1130,23 @@ class WithAttributes:
testtools.testcase.MyTest/test_bar[foo]
"""

_get_test_method: Any # Provided by the class we're mixed with
# Provided by the class we're mixed with
_get_test_method: Callable[[], Callable[[], object]]

def id(self) -> str:
orig = cast(str, super().id()) # type: ignore[misc]
orig = super().id() # type: ignore[misc]
assert isinstance(orig, str), (
f"Expected str from super().id(), got {type(orig)}"
)
# Depends on testtools.TestCase._get_test_method, be nice to support
# plain unittest.
fn = self._get_test_method()
attributes = cast(str, getattr(fn, "__testtools_attrs", None))
attributes = getattr(fn, "__testtools_attrs", None)
if not attributes:
return orig
assert isinstance(attributes, set), (
f"Expected set for __testtools_attrs, got {type(attributes)}"
)
return orig + "[" + ",".join(sorted(attributes)) + "]"


Expand Down