[TIP] tox, 2to3 and py.test

holger krekel holger at merlinux.eu
Mon Apr 2 21:27:32 PDT 2012


Hi Florian, all,

thanks for describing in good detail the problem.  I think it is also present
with nose and other tools using testdirs not contained in app packages.
IIRC Kumar mentioned a similar problem last year.

I think tox needs to learn to better support 2to3 for such testdirs.
Not sure at the moment how best to.  What about a config variable that
names a testdir like "test" in your first example and another config
option that tells tox to run the 2to3 process?

In any case, feel free to open a tox issue about the need of 2to3 for
external tests.

best,
holger


On Mon, Apr 02, 2012 at 08:11 +0000, Florian Bauer wrote:
> Hi all,
> 
> I am looking for a good solution for a project that should be tested both under 2.x and 3.x. I would like to use the following source code layout:
> 
>  mypackage/__init__.py
>  test/
> 
> The py.test documentation recommends that test/ should not be a package, and I understand why.
> 
> My setup.py looks like this:
> 
> import sys
> from distribute_setup import use_setuptools
> use_setuptools()
> from setuptools import setup
> from setuptools import find_packages
> 
> kw = {}
> if sys.version_info >= (3,):
>     kw['use_2to3'] = True
> 
> 
> setup(
>     setup_requires=["Sphinx"],
>     install_requires=["pyyaml",
>                       "mock==0.7.2",
>                       "pytest>=2.2.0",
>                       "unum"],
>     name = "mypackage",
>     version = "0.2",
>     packages = find_packages(),
>     **kw
> )
> 
> As you can see, I am running 2to3 as part of the install process. 
> The problem is that this does not convert the test to python3 syntax.
> 
> Currently, my workaround is to use a mypackage.test sub-package, which gives me the following source layout:
> 
> mypackage/__init__.py
> mypackage/test/__init__.py
> 
> I am using the following  tox.ini:
> 
> [tox]
> envlist = py26,py32
> 
> [testenv]
> 
> deps=
>     pytest
>     sphinx
> sitepackages=True
> commands=
>     py.test [] {envdir}/lib/site-packages/mypackage/test
>     sphinx-build -b doctest doc html
>     sphinx-build doc html
> 
> [testenv:py32]
> deps=
>     sphinx==dev
>     pytest
>     https://bitbucket.org/kiv/unum/get/tip.zip#egg=unum-4.1.1-dev
> commands=
>     py.test [] {envdir}/lib/site-packages/mypackage/test
> 
> 
> It works, but I do not like the fact that I am running py.test in site-packages .
> 
> Is there a cleaner solution?
> The only one coming to my mind is to write the tests in a version-agnostic way, using the six library.
> 
> Thanks,
> Florian
> 
> _______________________________________________________________________________________
> 
> Dialog Semiconductor GmbH
> Neue Str. 95
> D-73230 Kirchheim
> Managing Directors: Dr. Jalal Bagherli, Jean-Michel Richard
> Chairman of the Supervisory Board: Gregorio Reyes
> Commercial register: Amtsgericht Stuttgart: HRB 231181
> UST-ID-Nr. DE 811121668
> 
> 
> Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and 
> contains proprietary information, some or all of which may be legally privileged. It is 
> intended solely for the use of the individual or entity to which it is addressed. Access 
> to this email by anyone else is unauthorized. If you are not the intended recipient, any
> disclosure, copying, distribution or any action taken or omitted to be taken in reliance
> on it, is prohibited and may be unlawful.
> 
> Please consider the environment before printing this e-mail
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
> 



More information about the testing-in-python mailing list