python-3.x - 在 Google Cloud Build 中运行 python 单元测试
问题描述
我希望 Google Cloud Build 在推送更改后运行我在 python 项目中的单元测试。我能够配置运行测试的步骤,但我不确定如何输入保存测试的目录,如果我只是把.
它运行 0 test
我的项目结构是: - project_name - package_name - test - 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
如果我用 just .
then 替换文件夹,它会运行但没有发现任何测试。为了将代码复制到 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
文件。
推荐阅读
- apache-kafka - 重新部署后,kafka 流抱怨内部主题的分区无效。为什么会这样?
- msbuild - 无法使用 nuget pack 打包我的 .net 核心应用程序
- python - 进程运行时的 Tkinter 弹出窗口
- node.js - Windows 任务计划程序不运行带有参数的节点应用程序
- powershell - 使用 Select-String 在字符串中查找所需的字符串
- c++ - XFixesGetCursorImage 总是返回空名称和原子
- asp.net - 如何限制 IIS 中传入的 http 请求?
- python - 使用 python pandas 读取 sharepoint excel 文件
- r - 取消对 Quanteda 令牌对象的令牌化
- python - 使用python的三对角粗麻布