use*_*562 5 pytest python-3.x google-cloud-platform google-cloud-functions google-cloud-build
我的项目结构如下:
cloudbuild.yaml
requirements.txt
functions/
folder_a/
test/
main_test.py
main.py
Run Code Online (Sandbox Code Playgroud)
我的 cloudbuild.yaml
steps:
# Install
- name: 'docker.io/library/python:3.7'
args: ['pip', 'install', '-t', '/workspace/lib', '-r', 'requirements.txt']
# Test
- name: '?'
args: ['pytest', 'functions/**/*_test.py']
Run Code Online (Sandbox Code Playgroud)
我使用什么构建器来运行 pytest?我刚刚使用上一个安装步骤安装了它。我应该使用相同的 docker 镜像吗?在 pytest 成功完成所有测试之前,如何阻止我的构建通过?
每个步骤都在一个单独的容器中运行,因此您应该在一个步骤中完成所有操作:
steps:
# This step runs the unit tests on the app
- name: 'docker.io/library/python:3.7'
id: Test
entrypoint: /bin/sh
args:
- -c
- 'pip install -t /workspace/lib -r requirements.txt && pytest functions/**/*_test.py'
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅“使用 Cloud Build 进行 GitOps 式持续交付”。