python-3.x - 在 Google Build cloudbuild.yaml 中运行 pytest 以确定构建是否通过

标签 python-3.x google-cloud-platform google-cloud-functions pytest google-cloud-build

我的项目结构如下:

cloudbuild.yaml
requirements.txt
functions/
    folder_a/
        test/
            main_test.py
        main.py

我的 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']

我使用什么构建器来运行 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'

"GitOps-style continuous delivery with Cloud Build"更多细节。

关于python-3.x - 在 Google Build cloudbuild.yaml 中运行 pytest 以确定构建是否通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56469381/

相关文章:

python3.5 : asyncio, 如何等待 "transport.write(data)"完成或返回错误?

python-3.x - python中文本清理/处理的管道

google-cloud-platform - Dialogflow 中的多个快速回复

google-cloud-platform - GCP 发布订阅 : "The request was aborted because there was no available instance." - Doesn't Retry on Failure

google-cloud-firestore - 是否有响应代码可将 Google Cloud 任务标记为永久失败,以便它不会重试?

javascript - 写入数据库时​​未触发 Firebase 功能

python-3.x - 如何在 Python 3.7.x 中使用带有 @dataclass 的 list[customClass] 作为类型

go - 如何在 GCP 云功能中加载本地 Assets ?

node.js - NodeJS 示例 - Firebase Cloud Functions - 实例化 Admin SDK 目录服务对象

python-3.x - 在 Pandas 和 Numpy 中合并 DataFrame