83

I would like to use tox to run my unittests in two virtualenvs, since my application has to support 2 different Python versions.

My problem is that tox requires a setup.py, but I have none since my application is not a module and has its own installer. For now I don't want to go through the hassle of automating the install process as to work with setup.py, I just want to run my unittests without having to write a setup.py.

Is that possible? Or how can I write an "empty" setup.py that simply does nothing? Can you point me towards some documentation on the subject (the distutils documentation explains how to write a meaningful setup.py, not an empty one)?

Kjir
  • 4,437
  • 4
  • 29
  • 34

4 Answers4

102

After digging inside the source code, I found a scarcely documented option in tox.ini that skips sdist:

[tox]
skipsdist = BOOL    # defaults to false

Setting this to True I got what I wanted, saving me the effort of writing a meaningful setup.py

Shubham Chaudhary
  • 47,722
  • 9
  • 78
  • 80
Kjir
  • 4,437
  • 4
  • 29
  • 34
58

If you have an application (with a requirements.txt), rather than a project that you are going to distribute (which would have a setup.py instead), your tox.ini should look something like this:

[tox]
skipsdist = True

[testenv]
deps = -r{toxinidir}/requirements.txt

Found this answer originally from David Murphy's blog, but the page is no longer available, you can find an archived version here: https://web.archive.org/web/20150112223937/https://blog.schwuk.com/2014/03/19/using-tox-django-projects/

(Original link, now dead: http://blog.schwuk.com/2014/03/19/using-tox-django-projects/ )

mit
  • 11,083
  • 11
  • 50
  • 74
Ceasar
  • 22,185
  • 15
  • 64
  • 83
  • 1
    If you're going to do this, you might also be looking to set the PYTHONPATH, to do this just do `setenv = # newline PYTHONPATH = .` under [testenv] – ZN13 Aug 09 '17 at 18:34
  • SO's comment formatting can be confusing at first on conveying what @ZN13 is instructing us. See https://stackoverflow.com/a/47339689/1877509 on how it looks in a `tox.ini` file. – Axel Advento Mar 19 '21 at 05:22
3

This is my tox.ini file content for Django project by multiple settings:

[tox]
envlist = py36-{accounting,content,media}_settings
skipsdist = true

[testenv]
commands = python {toxinidir}/manage.py test
deps = -r{toxinidir}/requirements.txt

setenv =
    accounting_settings: DJANGO_SETTINGS_MODULE=my_project.settings.accounting
    contents_settings: DJANGO_SETTINGS_MODULE=my_project.settings.contents
    media_settings: DJANGO_SETTINGS_MODULE=my_project.settings.media
vvvvv
  • 25,404
  • 19
  • 49
  • 81
M.javid
  • 6,387
  • 3
  • 41
  • 56
2

I also had to remove usedevelop = true from my conf.

My configuration was looking like that:

[tox]
envlist = flake8,py36

[testenv]
usedevelop = true
install_command = pip install -U {opts} {packages}
deps =
    py36: -r requirements.txt
    py36: -r requirements-test.txt
    flake8: flake8
commands=
    flake8: flake8 app tests --ignore=E501,W503
    py36: pytest {toxinidir}/tests {posargs}

I added skipsdist = true as the other answers suggest. But it was not enough. As said above, also removing usedevelop = true did the trick.

vvvvv
  • 25,404
  • 19
  • 49
  • 81