Improve py3compat for tests.