| 183 | |
| 184 | == Catching string/bytes issues == |
| 185 | |
| 186 | The following can cause bugs and aren't always caught in tests: |
| 187 | |
| 188 | * `str(some_bytes)` (used to return `"hello"`, now returns `"b'hello'"`) |
| 189 | * `"%s" % (some_bytes,)` |
| 190 | * `some_bytes == some_unicode` |
| 191 | |
| 192 | Python 3 has a `-b` command line flag for `python` that turns these into warnings. In the test runner you can then setup a warnings filter that turns those into exceptions for the package being ported (3rd party packages might do this too, and don't want to fail tests because of them). This helps catch bugs that wouldn't be caught otherwise. The cost is that you also need to fix all the logging messages that do this, but ... that's probably worth it. |
| 193 | |
| 194 | tox.ini setup for Python 3 now has this setup for Tahoe-LAFS, so if you get BytesWarning as exception that's what's going on. For debugging purposes it can be useful to disable the exceptions and just look at the warnings; warnings don't fail the tests, so you can grep for them from tests output, sort and uniquify and then fix them in one go. |