Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tox default dependency for all environments

I have a tox.ini file and want to test on different django versions:

[tox]
envlist =
    py27-django16-{[base]deps]
    py32-django16-{[base]deps]
    py27-django17-{[base]deps]
    py32-django17-{[base]deps]

[base]
deps =
    nose

[testenv]
commands =
    {envpython} setup.py nosetests
basepython =
    py27: python2.7
    py32: python3.2

deps =
    django16: Django>=1.6,<1.7
    django17: Django>=1.7,<1.8

But it does not work and raise exception that invalid command 'nosetests', i think that because nose is not installed.

like image 603
ololoshka Avatar asked Oct 28 '25 08:10

ololoshka


1 Answers

Your tox.ini has two problems:

First: the generated environment names in envlist

([email protected]) 17:26:11 oliver@ob1 [1] < ~/work/tox/tests >  1744 %
tox -l
py27-django16-{[base]deps]
py32-django16-{[base]deps]
py27-django17-{[base]deps]
py32-django17-{[base]deps]

As you see, nothing is done with your entries as the curly brackets are not closed. But even if they were closed the substitution would not be happening as the referral to the deps does not belong there. What you want to say to generate the right environments for your needs looks like this (if I guess your intentions correctly - otherwise please clarify in a comment):

envlist = {py27,py32}-django{16,17}

This generates these environment names:

([email protected]) 17:26:20 oliver@ob1 [0] < ~/work/tox/tests >  1745 %
tox -l
py27-django16
py27-django17
py32-django16
py32-django17

You can then use the factors (e.g. py27 or django16) to specify what has to happen when as you are doing it correctly already. It's hard to get your head around this concept, but this might get you started. Also have a look at the docs about this feature - IMO they explain it quite well.

The main problem is that you need to refer to the deps where you need them - in the deps entry of your testenv section as outlined in the tox configuration specification.

A minimal working example would be:

[base]
deps = nose

[testenv]
deps = {[base]deps}  # <-- reference your base deps here
commands = pip freeze

The adpated tox.ini from your question would now look like:

[tox]
envlist = {py27,py32}-django{16,17}

[base]
deps = nose

[testenv]
commands = {envpython} setup.py nosetests
basepython =
    py27: python2.7
    py32: python3.2
deps =
    {[base]deps}
    django16: Django>=1.6,<1.7
    django17: Django>=1.7,<1.8

In your case though - when you just want to install it in all environments you don't even need the detour through a [base] section. So the recommended tox.ini in your case would be:

[tox]
envlist = {py27,py32}-django{16,17}

[testenv]
basepython =
    py27: python2.7
    py32: python3.2
deps =
    nose  # just add the dep here unconditionally for all envs
    django16: Django>=1.6,<1.7
    django17: Django>=1.7,<1.8
commands = {envpython} setup.py nosetests
like image 67
Oliver Bestwalter Avatar answered Oct 30 '25 15:10

Oliver Bestwalter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!