merge of #1402 make real tests friendly

A continuance of the #1402 bug, this makes sure that the real tests use the chosen driver, rather than defaulting to the system-installed version
Use Python 2 and 3 dict iteration methods.
Use the Python print function instead of statements.
Python 3 does not have unicode and long types.
Remove the xrange function to support Python 3.
Use the builtin next to support iterators in Python 2 and 3
Replace types.StringType with str for Python 3
Change how a code object is retrieved depending on the Python version.