unittest: Support TestCase subclasses with own runTest() method.

E.g. for doctest.

Signed-off-by: Paul Sokolovsky <pfalcon@users.sourceforge.net>
pull/488/head
Paul Sokolovsky 2021-10-23 18:09:32 +03:00 zatwierdzone przez Andrew Leech
rodzic ac282d861e
commit f92833b015
1 zmienionych plików z 33 dodań i 25 usunięć

Wyświetl plik

@ -302,11 +302,8 @@ def run_suite(c, test_result):
set_up = getattr(o, "setUp", lambda: None) set_up = getattr(o, "setUp", lambda: None)
tear_down = getattr(o, "tearDown", lambda: None) tear_down = getattr(o, "tearDown", lambda: None)
exceptions = [] exceptions = []
for name in dir(o):
if name.startswith("test"): def run_one(m):
m = getattr(o, name)
if not callable(m):
continue
print("%s (%s) ..." % (name, c.__qualname__), end="") print("%s (%s) ..." % (name, c.__qualname__), end="")
set_up() set_up()
try: try:
@ -328,10 +325,21 @@ def run_suite(c, test_result):
print(" ERROR") print(" ERROR")
# Uncomment to investigate failure in detail # Uncomment to investigate failure in detail
# raise # raise
continue
finally: finally:
tear_down() tear_down()
o.doCleanups() o.doCleanups()
if hasattr(o, "runTest"):
name = str(o)
run_one(o.runTest)
return
for name in dir(o):
if name.startswith("test"):
m = getattr(o, name)
if not callable(m):
continue
run_one(m)
return exceptions return exceptions