I have setup.py that should support both Python 2 and 3.
This code currently works and installs in Python 2.x
If I add the use_2to3 = True
sentence to my setup.py, then the module can be installed in Python 3, however, do:
python setup.py test
It crashes because one of the tests uses the StringIO class and the import string in Python 3 (currently from StringIO import StringIO
, where in Python3 it should be from io import StringIO
I thought that after you add the use_2to3 keyword, all tests (including unittests) were processed on 2to3 before testing.
What am I missing? In case this helps, the bulk of my setup.py looks like this:
from setuptools import setup setup( name='myproject', version='1.0', description='My Cool project', classifiers = [ 'Programming Language :: Python', 'Programming Language :: Python :: 3', ], py_modules=['mymodule'], test_suite='test_mymodule', zip_safe=False, use_2to3 = True, )
Edit: The reason I feel that 2to3 does not start on python setup.py test
is because it explodes and the bottom of the stacktrace reads:
File "/home/aparkin/temp/mymodule/test_mymodule.py", line 18, in <module> from StringIO import StringIO
But if I ran 2to3 on test_mymodule.py, then this import line should have been reworked for:
from io import StringIO
And (in the worst case) the tests should just fail.