Skip to content

Commit 645c454

Browse files
fduwjjChao1Han
authored andcommitted
[c10d] Make test compatible for new pytest (pytorch#136158)
Temporary fix to the issue in pytorch#127517. Short-term fix following CPython: https://github.com/python/cpython/blob/51aefc5bf907ddffaaf083ded0de773adcdf08c8/Lib/unittest/case.py#L419-L426 Differential Revision: [D62878083](https://our.internmc.facebook.com/intern/diff/D62878083) Pull Request resolved: pytorch#136158 Approved by: https://github.com/fegin
1 parent 1c33f7f commit 645c454

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

torch/testing/_internal/common_distributed.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,14 @@ def __init__(self, method_name: str = "runTest", methodName: str = "runTest") ->
561561
if methodName != "runTest":
562562
method_name = methodName
563563
super().__init__(method_name)
564-
fn = getattr(self, method_name)
565-
setattr(self, method_name, self.join_or_run(fn))
564+
try:
565+
fn = getattr(self, method_name)
566+
setattr(self, method_name, self.join_or_run(fn))
567+
except AttributeError as e:
568+
if methodName != 'runTest':
569+
# we allow instantiation with no explicit method name
570+
# but not an *incorrect* or missing method name
571+
raise ValueError(f"no such test method in {self.__class__}: {methodName}") from e
566572

567573
def setUp(self) -> None:
568574
super().setUp()
@@ -1014,8 +1020,14 @@ def __init__(self, method_name: str = "runTest", methodName: str = "runTest") ->
10141020
if methodName != "runTest":
10151021
method_name = methodName
10161022
super().__init__(method_name)
1017-
fn = getattr(self, method_name)
1018-
setattr(self, method_name, self.join_or_run(fn))
1023+
try:
1024+
fn = getattr(self, method_name)
1025+
setattr(self, method_name, self.join_or_run(fn))
1026+
except AttributeError as e:
1027+
if methodName != 'runTest':
1028+
# we allow instantiation with no explicit method name
1029+
# but not an *incorrect* or missing method name
1030+
raise ValueError(f"no such test method in {self.__class__}: {methodName}") from e
10191031

10201032
def perThreadSetUp(self):
10211033
# super().setUp() # TestCase.setUp() calls torch.manual_seed()

0 commit comments

Comments
 (0)