我正在学习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中提到。当我在localhost上运行测试时,我没有收到任何错误?
我认为你走在了正确的轨道上。在我看来,您的CI失败了,因为black
正在查找要重新格式化的文件。CI中运行的black
版本可能与本地运行的版本不同,因此建议进行新的/不同的更改。
您可以查看Gitlab管道的输出,以查找其中使用的black
版本。如果版本与black
的本地版本不匹配,请尝试通过Gitlab使用的black
版本在本地运行文件,然后将更改后的文件提交到您的repo以触发CI。
没有完全解决失败的作业。作为gitlab的新手,由于我在本地运行时没有出现错误,唯一对我有效的方法是匹配requirements.txt中测试脚本中安装的测试阶段pip-python包,并注释掉flake8和black测试脚本。