Skip to content

Commit 91e617a

Browse files
committed
Treat methodName="runTest" similar to unittest.TestCase
pytest 8.2 relies on a feature of `unittest.TestCase` where the initialization of it with the default `methodName="runTest"` is treated specially, allowing it to insantiate even without `runTest` method actually existing. See under "Changed in Python 3.2" in unittest.TestCase docs This fixes the error with pytest 8.2: AttributeError: 'TestUtil' object has no attribute 'runTest'. Did you mean: 'subTest'? Fixes: #372 ref: https://docs.python.org/3/library/unittest.html#unittest.TestCase ref: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426 ref: pytest-dev/pytest#12263 (comment)
1 parent a481b55 commit 91e617a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

testtools/testcase.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,17 @@ def _run_teardown(self, result):
735735

736736
def _get_test_method(self):
737737
method_name = getattr(self, "_testMethodName")
738-
return getattr(self, method_name)
738+
try:
739+
m = getattr(self, method_name)
740+
except AttributeError:
741+
if method_name != "runTest":
742+
# We allow instantiation with no explicit method name
743+
# but not an *incorrect* or missing method name.
744+
raise ValueError(
745+
"no such test method in %s: %s" % (self.__class__, method_name)
746+
)
747+
else:
748+
return m
739749

740750
def _run_test_method(self, result):
741751
"""Run the test method for this test.

0 commit comments

Comments
 (0)