Skip to content

Commit 80aa9ce

Browse files
committed
fix runtest error
1 parent 4756aae commit 80aa9ce

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

mmengine/testing/_internal/distributed.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,25 @@ def wrapper(self):
9292
# Constructor patches current instance test method to
9393
# assume the role of the main process and join its subprocesses,
9494
# or run the underlying test function.
95-
def __init__(self, method_name: str = 'runTest') -> None:
95+
def __init__(self,
96+
method_name: str = 'runTest',
97+
methodName: str = 'runTest') -> None:
98+
# methodName is the correct naming in unittest
99+
# and testslide uses keyword arguments.
100+
# So we need to use both to 1) not break BC and, 2) support testslide.
101+
if methodName != 'runTest':
102+
method_name = methodName
96103
super().__init__(method_name)
97-
fn = getattr(self, method_name)
98-
setattr(self, method_name, self.join_or_run(fn))
104+
try:
105+
fn = getattr(self, method_name)
106+
setattr(self, method_name, self.join_or_run(fn))
107+
except AttributeError as e:
108+
if methodName != 'runTest':
109+
# we allow instantiation with no explicit method name
110+
# but not an *incorrect* or missing method name
111+
raise ValueError(
112+
f'no such test method in {self.__class__}: {methodName}'
113+
) from e
99114

100115
def setUp(self) -> None:
101116
super().setUp()

0 commit comments

Comments
 (0)