Noob正在使用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
,以便构建可以找到我的测试。
这是我的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']
答案 0 :(得分:1)
您有一个自定义生成器,但我不知道它是如何工作的。也许可以使用绝对路径,这应该是问题所在。
无论如何,解决问题的一种简单方法是将存储库克隆到当前目录中,我的意思是在/workspace/
中
# Step 0, simply add a . as final arg
- name: 'gcr.io/cloud-builders/git'
args: ['clone', '--recurse-submodules', 'https://github.com/GDBSD/gcp-cicd-workflow', '.']