I have a testing environment in the following way
request1 = b"""INVITE sip:foo SIP/2.0
From: mo
To: joe
Content-Length: 4
1234
lalalal""".replace(b"\n", b"\r\n")
class MessageParsingTests(unittest.TestCase):
def setUp(self):
self.l = []
self.parser = sip.MessagesParser(self.l.append)
def feedMessage(self, message):
self.parser.dataReceived(message)
self.parser.dataDone()
def testSimple(self):
l = self.l
self.feedMessage(request1)
self.assertEqual(len(l), 1)
Now this test works fine on Python 2 but fails on Python 3. with the following traceback
[FAIL]
Traceback (most recent call last):
File "/home/ac/twisted-8673/twisted/test/test_sip.py", line 126, in testSimple
self.assertEqual(len(l), 1)
File "/home/ac/twisted-8673/twisted/trial/_synctest.py", line 425, in assertEqual
super(_Assertions, self).assertEqual(first, second, msg)
File "/usr/lib/python3.5/unittest/case.py", line 820, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/lib/python3.5/unittest/case.py", line 813, in _baseAssertEqual
raise self.failureException(msg)
twisted.trial.unittest.FailTest: 0 != 1
twisted.test.test_sip.MessageParsingTests.testSimple
I don't understand where the list appending occurs in this code. and what exactly happens in this line self.parser = sip.MessagesParser(self.l.append)
. I can see that call to feedMessage
method causes list appending in Python2 but didn't understand that either.
Any help is appreciated
Aucun commentaire:
Enregistrer un commentaire