I just migrated a cherrypy app from 2.7 to python (running on 3.6). I had a bunch of tests setup before based on this recipe. The point of the recipe is to emulate the network and perform tests units on individual endpoints.
Now my server on its own seems to run fine. However if I run the test units, they mostly return errors in py3 (all pass in py2), which seems to have to do about the response being in bytes (in py3) as opposed to string (in py2).
A test response
======================================================================
FAIL: test_index (__main__.EndpointTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/anonymous/PycharmProjects/server-py3/tests/test_DServer.py", line 67, in test_index
self.assertEqual(response.body, ['Hello World!'])
AssertionError: Lists differ: [b'Hello World!'] != ['Hello World!']
First differing element 0:
b'Hello World!'
'Hello World!'
- [b'Hello World!']
? -
+ ['Hello World!']
Similarly:
======================================================================
FAIL: test_valid_login (__main__.EndpointTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/anonymous/PycharmProjects/server-py3/tests/test_DServer.py", line 73, in test_valid_login
self.assertEqual(response.output_status, '200 OK')
AssertionError: b'200 OK' != '200 OK'
I know that the behavior is somewhat different with regards to bytes (such as explained here).
Actually 2 questions:
What's the best way to deal with this in my test? Do I need to prepend b in front of every string that is asserted in the server response?
Quick test on the server seems to indicate it works. However am I likely be bitten by this issue in other fashion? Any words of wisdom as to other gotchas with cherrypy & migration to py3?
I am not supporting py2 after that, I can do a clean migration.