首页 > 解决方案 > 是否可以在 tox 中运行广度优先而不是深度优先?

问题描述

我有一套小型测试总共需要大约 40 秒才能运行,我有一套中等测试总共需要大约 40 分钟才能运行。

我希望订单像这样运行:

  1. py27小测试
  2. py37小测试
  3. py27 中等测试
  4. py37 中等测试

相反, tox 运行它就像

  1. py27小测试
  2. py27 中等测试
  3. py37小测试
  4. py37 中等测试

这样做的问题是,如果一些简单的事情破坏了一个小测试,我想立即知道它。中等测试(如集成测试)是额外的安全层,可以排除更多问题,但需要更长的时间才能完成。

[tox]
envlist = py27,py37
[testenv:py27]
deps =
    pytest
    pytest-cov
    pytest-mock
    pylint
    ; packages specified by the setup.py cover the other dependencies for py2.7
commands =
    pytest -v --ignore-glob="*medium*" --doctest-modules
    pytest -v tests/medium_tests 

标签: pythontestingcontinuous-integrationautomated-teststox

解决方案


我不是毒物专家,但这样的事情可能会有所帮助:

[tox]
envlist = {s,m}-{py27,py37}

[testenv]
deps =
    pytest
commands =
    s: pytest -v -k 'not medium'
    m: pytest -v -k 'medium'

你所有的短测试命令都应该有前缀s:,所有中等测试命令都应该有前缀m: 。重要的是 env 列表{s,m}-{py27,py37}将按顺序通过s-py27, s-py37, m-py27,运行m-py37


推荐阅读