【问题标题】:testdriven.io flask-tdd-docker course chapter 15 pipeline stage test ERROR: Job failed: exit code 1testdriven.io flask-tdd-docker 课程第 15 章管道阶段测试错误:作业失败:退出代码 1
【发布时间】:2020-10-24 14:13:51
【问题描述】:

我正在关注 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 中提到的“调整阈值或提高覆盖率”。我在 localhost 上运行测试时没有收到任何错误?

【问题讨论】:

    标签: gitlab testdriven.io


    【解决方案1】:

    我认为你在正确的轨道上。在我看来,您的 CI 失败了,因为 black 正在查找要重新格式化的文件。在您的 CI 中运行的 black 版本可能与在本地运行的版本不同,因此建议进行新的/不同的更改。

    您可以查看您的 Gitlab 管道的输出,了解那里使用的 black 版本。如果版本与您的本地版本 black 不匹配,请尝试通过 Gitlab 使用的 black 版本在本地运行您的文件,然后将这些更改的文件提交到您的 repo 以触发您的 CI。

    【讨论】:

    • 我将 CI 中的 pip 安装更改为运行相同的版本,但仍然存在问题。
    • 我猜你在test 阶段之前有一个build 阶段?在构建稍后测试的映像时,您是否使用了一致版本的 black?
    • 当更新 requirements.txt 以匹配它工作的所有 lint 检查时
    【解决方案2】:

    没有完全解决失败的工作。作为 gitlab 新手,因为我在本地运行时没有出错,所以唯一对我有用的是匹配 test stage pip python packages install in test scripts in requirements.txt 并注释掉 flake8 和 black 测试脚本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2020-01-01
      • 2016-04-11
      • 1970-01-01
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多