Skip to content

Commit 7e12a30

Browse files
committed
Fix issue with deprecated function in test
- assert_ was removed in Python 3 and later removed - Fixed the script to error out correctly when the tests fail - The RunClientServer.py test did not fail as expected on this error
1 parent ed4fb5e commit 7e12a30

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/py/TestSocket.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import time
2525
import socket
2626
import random
27+
import sys
2728

2829

2930
class TimeoutTest(unittest.TestCase):
@@ -51,7 +52,7 @@ def testConnectTimeout(self):
5152
socket.open()
5253
leaky.append(socket)
5354
except Exception:
54-
self.assert_(time.time() - starttime < 5.0)
55+
self.assertTrue(time.time() - starttime < 5.0)
5556

5657
def testWriteTimeout(self):
5758
starttime = time.time()
@@ -65,7 +66,7 @@ def testWriteTimeout(self):
6566
lsock.write("hi" * 100)
6667

6768
except Exception:
68-
self.assert_(time.time() - starttime < 5.0)
69+
self.assertTrue(time.time() - starttime < 5.0)
6970

7071

7172
if __name__ == '__main__':
@@ -75,4 +76,10 @@ def testWriteTimeout(self):
7576
suite.addTest(loader.loadTestsFromTestCase(TimeoutTest))
7677

7778
testRunner = unittest.TextTestRunner(verbosity=2)
78-
testRunner.run(suite)
79+
result = testRunner.run(suite)
80+
81+
# Exit with non-zero code if tests failed
82+
if result.failures or result.errors:
83+
sys.exit(1)
84+
else:
85+
sys.exit(0)

0 commit comments

Comments
 (0)