[TIP] Converting a project from setup.py test to py.test

Paul Moore p.f.moore at gmail.com
Mon Jul 28 13:37:59 PDT 2014


I have a project that currently uses tox and setup.py test to run its
tests. Basically, tox.ini has a series of sections

[testenv:py26]
deps = -r{toxinidir}/requirements/test_26.txt
commands = python setup.py test

and the tests are in a directory "tests" alongside setup.py and the
project directory.

I want to change tox.ini to use py.test - this is basically for
personal use, so I want to make the changes as non-intrusively as
possible. For better or worse, the test directory is *not* installed
with the project code.

I tried what I thought was the obvious approach, changing tox.ini to have

[testenv:py27, pypy]
commands = py.test {toxinidir}/tests {posargs}
deps = pytest mock

But when I run tox -e py27 -r -v, the build shows pip being used to
install only the project, and not pytest or mock:

>tox -e py27 -r -v
using tox.ini: C:\Work\Projects\cookiecutter\Dev\cookiecutter\tox.ini
using tox-1.7.2 from C:\Apps\Python34\lib\site-packages\tox\__init__.py
GLOB sdist-make: C:\Work\Projects\cookiecutter\Dev\cookiecutter\setup.py
  C:\Work\Projects\cookiecutter\Dev\cookiecutter$
C:\Apps\Python34\python.exe
C:\Work\Projects\cookiecutter\Dev\cookiecutter\setup.py sdist
--formats=zip --dist-dir
C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\dist
>C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\log\tox-0.log
py27 recreate: C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\py27
  C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox$
C:\Apps\Python34\python.exe -mvirtualenv --setuptools --python
C:\Apps\Python27\python.exe py27
>C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\py27\log\py27-0.log
py27 inst: C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\dist\cookiecutter-0.7.1.zip
  C:\Work\Projects\cookiecutter\Dev\cookiecutter$
C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\py27\Scripts\pip.EXE
install --pre C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\dist\cookiecutter-0.7.1.zip
>C:\Work\Projects\cookiecutter\Dev\cookiecutter\.tox\py27\log\py27-1.log
py27 runtests: PYTHONHASHSEED='946'
___________________________________ summary ___________________________________
  py27: commands succeeded
  congratulations :)

It seems to me that there must be something trivial I'm doing wrong,
but I'm blowed if I can see it. Can anyone help?

Just to be clear, I'd like to confine my changes just to tox.ini, if
at all possible. This is purely for local use and I want to avoid
altering the project files if possible.

Thanks,
Paul



More information about the testing-in-python mailing list