Skip to content

Commit 42a4f8b

Browse files
committed
unittest: use None instead of empty string for 'msg' arg of assert_* methods
Fix typo in ERROR handling Fail program if errors found in addition to failures
1 parent 72c5230 commit 42a4f8b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

unittest/unittest.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class TestCase:
2626
def fail(self, msg=''):
2727
assert False, msg
2828

29-
def assertEqual(self, x, y, msg=''):
29+
def assertEqual(self, x, y, msg=None):
3030
if not msg:
3131
msg = "%r vs (expected) %r" % (x, y)
3232
assert x == y, msg
3333

34-
def assertNotEqual(self, x, y, msg=''):
34+
def assertNotEqual(self, x, y, msg=None):
3535
if not msg:
3636
msg = "%r not expected to be equal %r" % (x, y)
3737
assert x != y, msg
@@ -57,7 +57,7 @@ def assertAlmostEqual(self, x, y, places=None, msg='', delta=None):
5757

5858
assert False, msg
5959

60-
def assertNotAlmostEqual(self, x, y, places=None, msg='', delta=None):
60+
def assertNotAlmostEqual(self, x, y, places=None, msg=None, delta=None):
6161
if delta is not None and places is not None:
6262
raise TypeError("specify delta or places not both")
6363

@@ -76,37 +76,37 @@ def assertNotAlmostEqual(self, x, y, places=None, msg='', delta=None):
7676

7777
assert False, msg
7878

79-
def assertIs(self, x, y, msg=''):
79+
def assertIs(self, x, y, msg=None):
8080
if not msg:
8181
msg = "%r is not %r" % (x, y)
8282
assert x is y, msg
8383

84-
def assertIsNot(self, x, y, msg=''):
84+
def assertIsNot(self, x, y, msg=None):
8585
if not msg:
8686
msg = "%r is %r" % (x, y)
8787
assert x is not y, msg
8888

89-
def assertIsNone(self, x, msg=''):
89+
def assertIsNone(self, x, msg=None):
9090
if not msg:
9191
msg = "%r is not None" % x
9292
assert x is None, msg
9393

94-
def assertIsNotNone(self, x, msg=''):
94+
def assertIsNotNone(self, x, msg=None):
9595
if not msg:
9696
msg = "%r is None" % x
9797
assert x is not None, msg
9898

99-
def assertTrue(self, x, msg=''):
99+
def assertTrue(self, x, msg=None):
100100
if not msg:
101101
msg = "Expected %r to be True" % x
102102
assert x, msg
103103

104-
def assertFalse(self, x, msg=''):
104+
def assertFalse(self, x, msg=None):
105105
if not msg:
106106
msg = "Expected %r to be False" % x
107107
assert not x, msg
108108

109-
def assertIn(self, x, y, msg=''):
109+
def assertIn(self, x, y, msg=None):
110110
if not msg:
111111
msg = "Expected %r to be in %r" % (x, y)
112112
assert x in y, msg
@@ -119,7 +119,6 @@ def assertIsInstance(self, x, y, msg=None):
119119
def assertRaises(self, exc, func=None, *args, **kwargs):
120120
if func is None:
121121
return AssertRaisesContext(exc)
122-
123122
try:
124123
func(*args, **kwargs)
125124
assert False, "%r not raised" % exc
@@ -212,7 +211,7 @@ def run_class(c, test_result):
212211
except Exception as e:
213212
print(" ERROR\n")
214213
test_result.errorsNum += 1
215-
sys.print_exception(ae)
214+
sys.print_exception(e)
216215
print()
217216
finally:
218217
tear_down()
@@ -232,4 +231,4 @@ def test_cases(m):
232231
runner = TestRunner()
233232
result = runner.run(suite)
234233
# Terminate with non zero return code in case of failures
235-
sys.exit(result.failuresNum > 0)
234+
sys.exit(result.failuresNum + result.errorsNum > 0)

0 commit comments

Comments
 (0)