问题描述
由于依赖于本地运行的服务,一部分 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