【发布时间】:2020-04-18 16:21:13
【问题描述】:
使用 Cloud Build 的新手。尝试运行测试,但它缺少路径中的顶级项目文件夹。我不知道如何在构建步骤中解决这个问题。项目结构为:
gcp_cicd_workflow
|-- src
| my_module.py
|-- tests
| test_my_module.py
在云构建尝试运行测试时出现错误:
imported module 'test_my_module' has this __file__ attribute:
/workspace/gcp-cicd-workflow/tests/test_my_module.py
which is not the same as the test file we want to collect:
/workspace/tests/test_my_module.py
这对我来说非常有意义,因为默认情况下,Cloud Build 使用名为 /workspace 的目录作为工作目录。我需要做的是弄清楚如何创建路径 workspace/gcp-cicd-workflow 以便 build 可以找到我的测试。
这是我的完整 cloudbuild.yaml 文件(直到它出错:
steps:
# Step 0
- name: 'gcr.io/cloud-builders/git'
args: ['clone', '--recurse-submodules', 'https://github.com/GDBSD/gcp-cicd-workflow']
# Step 1
# Variable $COMMIT_SHA provided by the Cloud Build so we test the correct commit.
- name: 'gcr.io/cloud-builders/git'
args: [ 'checkout', '$COMMIT_SHA']
dir: 'gcp-cicd-workflow'
# Step 2
# Cloud Build automatically substitutes $PROJECT_ID for your Project ID
- name: 'gcr.io/$PROJECT_ID/python-cloudbuild'
entrypoint: '/bin/bash'
args: ['-c', 'python3 -m venv /workspace/venv']
# Step 3
# Installs any dependencies listed in the project's requirements.txt.
- name: 'gcr.io/$PROJECT_ID/python-cloudbuild'
entrypoint: 'venv/bin/pip'
args: ['install', '-V', '-r', 'requirements.txt']
# Step 4
# Runs pytest from the virtual environment (with all requirements)
# using the verbose flag so you can see each individual test.
- name: 'gcr.io/$PROJECT_ID/python-cloudbuild'
entrypoint: 'venv/bin/python'
args: ['-m', 'pytest', '-v']
【问题讨论】:
标签: python git google-cloud-platform google-cloud-build