I am trying to verify commands before placing them in tox.ini under [testenv] commands =
section.
Is it possible to pass custom command to tox
by passing it as shell arguments? Something like
tox -e <env_to_run_script_in> <command_which_we_want_to_run_in_specified_env>
I have tried the following but none of them works.
tox -e py34 args py.test
tox -e py34 -- py.test
tox args "py.test"
How can I run python commands/scripts in tox created virtual environments without placing them in tox.ini ?
Tox is a tool that creates virtual environments, and installs the configured dependencies for those environments, for the purpose of testing a Python package (i.e. something that will be shared via PyPi, and so it only works with code that defines a setup.py ).
[tox]envlist is only a default — a list of environments to run when tox is invoked without option -e and without TOXENV environment variable. Once you use tox -e [tox]envlist is ignored. You can run local environment with different python versions, but I don't know any way to run it multiple times.
By using posargs
with a default argument in the command specifier, arbitrary command lines can be passed to the underlying virtualenv environment while still running the tests when no arguments are passed.
Using a tox.ini
like
[tox]
envlist = py27,py35,pypy,pypy3
[testenv]
passenv =
TERM
deps=
pytest
ipython
six
commands={posargs:py.test}
When tox is invoked with no arguments, it defaults to running py.test
otherwise args passed on the command line are sent to the specified virtualenv.
Using a sample hello.py
in the root of your project
import os
import sys
print(os.__file__)
print(sys.version)
print("Hello from env")
called via tox -e pypy python hello.py
tox -e pypy
launches pypy virtualenv with the arguments python hello.py
Output:
/Users/seanjensengrey/temp/.tox/pypy/lib-python/2.7/os.pyc
2.7.10 (5f8302b8bf9f53056e40426f10c72151564e5b19, Jan 20 2016, 04:41:02)
[PyPy 4.0.1 with GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
Hello from env
I use TERM="xterm-256color" tox -e pypy ipython
to invoke an ipython shell with my package installed in the virtualenv.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With