Home > Software design >  How do I toggle verbose mode for all commands inside tox.ini in a simpler way?
How do I toggle verbose mode for all commands inside tox.ini in a simpler way?

Time:08-06

Let us say I have a lot of commands inside my tox.ini

commands =
        poetry install -v
        poetry run pytest --typeguard-packages=news --xdoctest --cov -vv
        poetry run flake8 --verbose
        poetry run black src tests --verbose
        poetry run isort . --verbose
        poetry run bandit src --recursive --verbose
        poetry run mypy src --verbose
        poetry run darglint src --verbosity=2
        poetry run darglint tests --verbosity=2

Instead of repeating verbose everywhere, is there a way I can make all of them run with/without verbose in a simpler way?

For example, if I ran

poetry run tox

it runs everything without verbose, if I remove the --verbose flag from everywhere but how do I make tox run all commands with verbose without hardcoding the verbose flag?

CodePudding user response:

No, there is no simpler way, as you can see that the commands take different arguments to run in verbose mode.

If all commands would take the same arguments, e.g. --verbose, you could do something like...

commands =
        poetry install {posargs}
        poetry run pytest --typeguard-packages=news --xdoctest --cov {posargs}
        poetry run flake8 {posargs}
        poetry run black src tests {posargs}
        ...

and then run

tox -e lint -- --verbose

That said... "there is no way" is a lie.

You could create a bash script and run that as a tox command instead of your current list.

P.S.: I am one of the tox maintainers, but not a bash guy :-) So good luck with that.

P.P.S.: Out of scope of this question, but you could have a look at https://pre-commit.com/ - this is the way most Python projects I know run linters nowadays.

P.P.P.S.: You could copy/paste your env, one time with and one time without the verbose mode.

  • Related