Tox:本地和 gitlab CI 运行期间的不同测试集

问题描述

由于依赖于本地运行的服务,一部分 pytest 测试无法在 gitlab 上运行。 如何将它们从 gitlab CI 管道中排除,同时保留它们用于本地测试?我不确定是否需要在 pytest、tox 或 gitlab 配置中完成过滤。

当前配置:

tox.ini

[testenv]
commands = pytest {posargs}
gitlab-ci.yml


build:
    stage: build
    script:
        - tox

解决方法

最方便的方法是动态地通过 pytest

def test_function():
    if not valid_config():
        pytest.xfail("unsupported configuration")

https://docs.pytest.org/en/latest/skipping.html

,

您也可以使用两个不同的 tox.ini 文件。

虽然 tox 默认查找 tox.ini,但您也可以传入一个单独的 tox.ini 文件,例如...

tox -c tox-ci.ini

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...