[TIP] tox, 2to3 and py.test
Florian Bauer
Florian.Bauer at diasemi.com
Mon Apr 2 01:11:40 PDT 2012
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
More information about the testing-in-python
mailing list