4

I would like to use different command line arguments for py.test, depending on environment: running locally there should be only default ones, but on Jenkins I would like to add --junitxml=junit-{envname}.xml, so the test results could be published in nice format. I know from documentation, that there is special [tox:jenkins] section, which should be used in case there is defined 'JENKINS_URL' or 'HUDSON_URL'. So now I created simple tox.ini file:

[tox]
envlist = py27, py35

[tox:jenkins]
commands = echo "We are in JENKINS!"

[testenv]
setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/my_module
commands = python setup.py test

deps =
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/requirements_test.txt

And have defined JENKINS_URL environment variable:

export JENKINS_URL=true

I expect, that if I run tox, then my original command will be substituted with echo, but it doesn't work, instead I end with original command been executed. Could someone help me with this problem?

grundic
  • 4,641
  • 3
  • 31
  • 47

2 Answers2

2

Okay, found the solution myself:

[tox]
envlist = py27, py35

[testenv]
setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/my_module
commands = py.test {env:CUSTOM_ARGS} ; <== use environment variable here

deps =
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/requirements_test.txt

and in Jenkins just define CUSTOM_ARGS environment variable like this:

export CUSTOM_ARGS="--junitxml=junit.xml"
grundic
  • 4,641
  • 3
  • 31
  • 47
1

You could have used positional arguments.

Like this:

commands = py.test --mandatory-flag {posargs:--default-flag}

And in Jenkins you can call tox like this:

tox -- --override-flag

Note the separation with two dashes --.

Havok
  • 5,776
  • 1
  • 35
  • 44