Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d9ca3d

Browse files
committed
unittest: Run test_* functions as well as TestCase classes.
1 parent c7eb3de commit 9d9ca3d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎python-stdlib/unittest/unittest.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,27 @@ def run_one(m):
332332
# raise
333333
finally:
334334
tear_down()
335-
o.doCleanups()
335+
try:
336+
o.doCleanups()
337+
except AttributeError:
338+
pass
336339

337340
if hasattr(o, "runTest"):
338341
name = str(o)
339342
run_one(o.runTest)
340343
return
341344

342345
for name in dir(o):
343-
if name.startswith("test"):
346+
if name.startswith("test_"):
344347
m = getattr(o, name)
345348
if not callable(m):
346349
continue
347350
run_one(m)
351+
352+
if callable(o):
353+
name = o.__name__
354+
run_one(o)
355+
348356
return exceptions
349357

350358

@@ -354,6 +362,8 @@ def test_cases(m):
354362
c = getattr(m, tn)
355363
if isinstance(c, object) and isinstance(c, type) and issubclass(c, TestCase):
356364
yield c
365+
elif tn.startswith("test_") and callable(c):
366+
yield c
357367

358368
m = __import__(module) if isinstance(module, str) else module
359369
suite = TestSuite(m.__name__)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /