Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minimize repetition in tox file

Goal: Successfully execute specific tox commands, and have it run for "just" that specific matched command.

Example: tox -e py35-integration

tox should run only for py35-integration and not including the default or standalone py35 definition.

I have tried two different approaches, which as far as I understand are the two ways to go about trying to do what I'm trying to do.

  • note the flake8 command is to easily isolate between different commands and indicate to me what is running. It is not an indication of the command I'm really trying to run.

Furthermore, ini files are only showing relevant parts.

First approach

[tox]
envlist = {py27,py35}, {py27,py35}-integration

[testenv]
commands =
    py27: python -m testtools.run discover
    py35: python -m testtools.run discover
    py27-integration: flake8 {posargs}
    py35-integration: flake8 {posargs}

With this approach, the understanding here is that I want to have tox -e py27-integration run without also running what is defined for the py27 command. This is not what is happening. Instead, it will run both py27 and py27-integration.

Second approach

[tox]
envlist = {py27,py35}, {py27,py35}-integration

[testenv]
commands =
    python -m testtools.run discover

[testenv:integration]
commands = 
    flake8 {posargs}

Now, here I am explicitly isolating for a "sub" environment with its own command to run for "integration".

However, unfortunately, I'm met with the exact same behaviour of all matched patterns of "py27" being executed.

I'm trying to avoid repeating testenv structures as: [testenv:py27-integration] and [testenv:py35-integration], which contain the exact same definitions (goal is to minimize repetition).

I would love to know if there is a way I can achieve what I am trying to do.

I do not want to venture down doing something like p27-integration as an alternative naming scheme, since our CI pipelines have templates expecting certain name structures, and these names are also idiomatic to tox, in that py27 for example is understood to install a 2.7 virtual environment.

like image 658
idjaw Avatar asked Jun 30 '17 15:06

idjaw


Video Answer


1 Answers

Updated

[tox]
minversion = 3.15
envlist = {py27,py35}, {py27,py35}-integration

[testenv]
commands =
    python -m testtools.run discover

[testenv:py{27,35}-integration]
commands = 
    flake8 {posargs}
like image 92
phd Avatar answered Oct 17 '22 20:10

phd