Python 如何使用tox.ini运行测试

Python 如何使用tox.ini运行测试,python,pytest,python-unittest,python-3.7,tox,Python,Pytest,Python Unittest,Python 3.7,Tox,我正在网上阅读并试图了解一些图书馆,我遇到了以下问题: [tox] envlist = py27 py35 py36 py37 flake8 [testenv:flake8] basepython = python deps = flake8 commands = flake8 related [testenv] setenv = PYTHONPATH = {toxinidir}:{toxinidir}/related deps =

我正在网上阅读并试图了解一些图书馆,我遇到了以下问题:

[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}
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
  • 没有pytest或unitest的测试
  • 我在网上阅读,发现一个tox.ini文件,如下所示:

    [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}
    
    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
    
    我仍然无法让它运行。我做了以下工作:

    [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}
    
    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
    
    如何运行此文件中的测试? 该库称为related:

    ,它可以为您运行一系列命令(类似于
    make
    ,但它知道python的事情)

    通常,当存在
    tox.ini
    时,运行测试的最简单方法是调用
    tox
    本身(您可以使用
    pip install tox
    进行安装)

    如果您想大致重现tox在引擎盖下所做的事情(比如上面的
    tox-epy37
    ),您需要创建一个virtualenv,然后调用测试

    # 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
    

    这些未知选项在您的应用程序中。删除它们,这些是用于
    flake8
    的选项,而不是
    pytest