繁体   English   中英

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

[英]testdriven.io flask-tdd-docker course chapter 15 pipeline stage test ERROR: Job failed: exit code 1

我正在关注 python/flask/docker教程 一切正常,直到我推送到 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 新手,自从我在本地运行时没有出现错误以来,唯一对我有用的是匹配测试阶段 pip python 包安装在 requirements.txt 的测试脚本中,并注释掉 flake8 和 black 测试脚本。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM