4

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

may
  • 1,073
  • 4
  • 14
  • 31
  • Those unknown options are in your [`pytest.ini`](https://github.com/genomoncology/related/blob/be47c0081e60fc60afcde3a25f00ebcad5d18510/pytest.ini#L5). Remove them, those are options for `flake8`, not `pytest`. – phd Feb 25 '19 at 20:26

1 Answers1

8

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
anthony sottile
  • 61,815
  • 15
  • 148
  • 207