From f09d2ec608f8238c7c88c04575c0bb3d87334ef8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 26 Feb 2020 15:03:46 +0200 Subject: [PATCH] unittest: Support both test classes and class instances. And for clarity, rename runner function run_class() -> run_suite(). Signed-off-by: Paul Sokolovsky --- python-stdlib/unittest/unittest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python-stdlib/unittest/unittest.py b/python-stdlib/unittest/unittest.py index 066ad361..55d002f4 100644 --- a/python-stdlib/unittest/unittest.py +++ b/python-stdlib/unittest/unittest.py @@ -180,7 +180,7 @@ class TestRunner: def run(self, suite): res = TestResult() for c in suite._tests: - res.exceptions.extend(run_class(c, res)) + res.exceptions.extend(run_suite(c, res)) print("Ran %d tests\n" % res.testsRun) if res.failuresNum > 0 or res.errorsNum > 0: @@ -216,8 +216,11 @@ def capture_exc(e): # TODO: Uncompliant -def run_class(c, test_result): - o = c() +def run_suite(c, test_result): + if isinstance(c, type): + o = c() + else: + o = c set_up = getattr(o, "setUp", lambda: None) tear_down = getattr(o, "tearDown", lambda: None) exceptions = []