我正在关注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上运行测试时,没有得到任何错误?
发布于 2020-10-28 00:38:08
我认为你在正确的轨道上。在我看来,您的配置项失败了,因为black正在查找要重新格式化的文件。您的配置项中运行的black版本可能与本地运行的版本不同,因此建议进行新的/不同的更改。
您可以查看Gitlab管道的输出,查找其中使用的black版本。如果版本与您的本地black版本不匹配,请尝试通过Gitlab使用的black版本在本地运行您的文件,然后将这些更改的文件提交到您的存储库以触发您的CI。
发布于 2020-10-27 23:47:47
未完全解决失败的作业。作为gitlab新手,当我在本地运行时没有错误,唯一对我有效的事情是匹配requirements.txt中测试脚本中安装的测试阶段pip python包,并注释掉flake8和black测试脚本。
https://stackoverflow.com/questions/64514265
复制相似问题