Fixed tests under Python3
Merging with upstream.