Skip to content

Commit f09d2ec

Browse files
pfalconpi-anl
authored andcommitted
unittest: Support both test classes and class instances.
And for clarity, rename runner function run_class() -> run_suite(). Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent d747b21 commit f09d2ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

python-stdlib/unittest/unittest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class TestRunner:
180180
def run(self, suite):
181181
res = TestResult()
182182
for c in suite._tests:
183-
res.exceptions.extend(run_class(c, res))
183+
res.exceptions.extend(run_suite(c, res))
184184

185185
print("Ran %d tests\n" % res.testsRun)
186186
if res.failuresNum > 0 or res.errorsNum > 0:
@@ -216,8 +216,11 @@ def capture_exc(e):
216216

217217

218218
# TODO: Uncompliant
219-
def run_class(c, test_result):
220-
o = c()
219+
def run_suite(c, test_result):
220+
if isinstance(c, type):
221+
o = c()
222+
else:
223+
o = c
221224
set_up = getattr(o, "setUp", lambda: None)
222225
tear_down = getattr(o, "tearDown", lambda: None)
223226
exceptions = []

0 commit comments

Comments
 (0)