gpt4 book ai didi

python-3.x - 在 Google Cloud Build 中运行 python 单元测试

转载 作者:行者123 更新时间:2023-12-03 23:13:25 25 4
gpt4 key购买 nike

我希望 Google Cloud Build 在推送更改后运行我在 python 项目中的单元测试。
我能够配置运行测试的步骤,但我不确定如何输入保存测试的目录,如果我只是输入 .然后它运行 0 测试

我的项目结构是:
- 项目名
- 包裹名字
- 测试
- sample_test.py

这是我的 cloudbuild.yaml配置:

steps:
- name: 'gcr.io/cloud-builders/docker'
args: ["run","gcr.io/google-appengine/python","python3","-m","unittest","discover","--verbose","-s","./package_name/test/","-p","*_test.py"]
id: unittest

以上失败并显示以下消息:
raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: './package_name/test/'
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
Show debug panel

如果我只用 . 替换文件夹然后它运行但没有发现任何测试。
为了将代码复制到 gs 存储桶,我们使用 gsutil 然后 ./package_name 将包复制到存储桶
在本地这当然有效

我如何才能了解运行测试的正确文件夹结构是什么?
谢谢!

最佳答案

  • 为什么要使用appengine容器?为什么不直接使用官方 Python 容器 - name: python:3.7 ?
    步骤作为 Docker 容器运行,当您想运行 docker 容器时,我认为没有理由在 docker 中运行 Docker。
    试试这个:
  • steps:
    - name: python:3.7
    args: ["python","-m","unittest","discover","--verbose","-s","./package_name/test/","-p","*_test.py"]
    id: unittest
  • 另外,你有没有__init__.py目录中的文件 ./package_name/test ?留言directory is not importable通常意味着这个目录不是 Python 包,因为缺少 __init__.py文件。
  • 关于python-3.x - 在 Google Cloud Build 中运行 python 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55022058/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com