Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run tests with tox.ini

I am reading and trying to understand some libraries online, and I come across the following:

  1. Tests with no pytest or unitest

I am reading online and I found a tox.ini file like the following:

[tox]
envlist =
    py27
    py35
    py36
    py37
    flake8

[testenv:flake8]
basepython = python
deps = flake8
commands = flake8 related

[testenv]
setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/related

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

commands =
    pip install -U pip
    py.test --basetemp={envtmpdir}

I am still not being able to make it run. I did the following:

pip install -U pip
py.test --basetemp={envtmpdir}
py.tests --basetemp={py37}

usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: --mccabe --pep8 --flake8
  inifile: /home/tmhdev/Documents/related/pytest.ini
  rootdir: /home/tmhdev/Documents/related

How can I run the tests in this file? The library is called related: https://github.com/genomoncology/related/tree/master/tests

like image 845
may Avatar asked Sep 19 '25 06:09

may


1 Answers

tox itself is an environment manager that can run a series of commands for you (think like make but it knows about python things)

Usually the easiest way to run tests when there is a tox.ini is to just invoke tox itself (which you can install with pip install tox)

If you want to reproduce ~roughly what tox is doing under the hood (let's say for tox -e py37 above) you'd need to create a virtualenv and then invoke the tests.

# environment setup
virtualenv -p python3.7 .tox/py37
. .tox/py37/bin/activate
.tox/py37/bin/pip install -r dev-requirements.txt
export PYTHONPATH=$PWD:$PWD/related

# testenv `commands`
pip install -U pip
py.test --basetemp=.tox/py37/tmp
like image 79
Anthony Sottile Avatar answered Sep 22 '25 01:09

Anthony Sottile