testdriven.io Flask-tdd-docker 课程第 15 章管道阶段测试错误:作业失败:退出代码 1

问题描述 投票:0回答:2

我正在关注 python/flask/docker tutorial 。一切都很完美,直到我推送到 GitLab 管道阶段构建良好,然后在测试阶段失败:

  stage: test
  image: $IMAGE:latest
  services:
    - postgres:latest
  variables:
    POSTGRES_DB: users
    POSTGRES_USER: runner
    POSTGRES_PASSWORD: runner
    DATABASE_TEST_URL: postgres://runner:runner@postgres:5432/users
  script:
    - python3.8 -m venv env
    - source env/bin/activate
    - pip install -r requirements.txt
    - pip install black flake8 isort pytest
    - pytest "project/tests" -p no:warnings
    - flake8 project
    - black project --check
    - isort project/**/*.py --check-only

管道测试日志:

$ pytest "project/tests" -p no:warnings
============================= test session starts ==============================
platform linux -- Python 3.8.1, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: /builds/piccoloa/flask-on-docker/project/tests, configfile: pytest.ini
collected 30 items
project/tests/test_config.py ...                                         [ 10%]
project/tests/test_ping.py .                                             [ 13%]
project/tests/test_users.py .............                                [ 56%]
project/tests/test_users_unit.py .............                           [100%]
============================== 30 passed in 0.41s ==============================
$ flake8 project
$ black project --check
would reformat /builds/piccoloa/flask-on-docker/project/api/users.py
would reformat /builds/piccoloa/flask-on-docker/project/tests/test_users.py
would reformat /builds/piccoloa/flask-on-docker/project/tests/test_users_unit.py
Oh no! 💥 💔 💥
3 files would be reformatted, 10 files would be left unchanged.
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1

发现了这个,但不知道如何修复或是否与问题相关。 GitLab Issue 中提到“调整阈值或提高覆盖范围”。当我在本地主机上运行测试时没有收到任何错误?

gitlab
2个回答
0
投票

我认为你走在正确的道路上。在我看来,您的 CI 失败是因为

black
正在寻找要重新格式化的文件。您的 CI 中运行的
black
版本可能与本地运行的版本不同,因此建议新的/不同的更改。

您可以查看 Gitlab 管道的输出,了解其中使用的

black
版本。如果版本与您本地的
black
版本不匹配,请尝试通过 Gitlab 使用的
black
版本在本地运行您的文件,然后将这些更改的文件提交到您的存储库以触发您的 CI。


0
投票

尚未完全解决失败的工作。作为 gitlab 新手,自从我在本地运行时没有出现错误以来,唯一对我有用的就是匹配测试阶段 pip python 包安装在 requests.txt 的测试脚本中,并注释掉 flake8 和 black 测试脚本。

© www.soinside.com 2019 - 2024. All rights reserved.