【问题标题】:Run pytest in Google Build cloudbuild.yaml to determine if build passes or not在 Google Build cloudbuild.yaml 中运行 pytest 以确定构建是否通过
【发布时间】:2019-06-05 23:45:33
【问题描述】:

我的项目结构如下:

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 成功完成所有测试之前,如何阻止我的构建通过?

【问题讨论】:

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


    【解决方案1】:

    每个步骤都在单独的容器中运行,因此您应该一步完成:

    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"

    【讨论】:

    • ERROR: build step 0 "python:3.7-slim" failed: exit status 127 ... /bin/sh: 1: pytest: not found 的错误
    • 我将.. && pytest ... 更改为.. && /lib/bin/pytest ... 并得到了新的错误:File "/workspace/lib/bin/pytest", line 6, in <module> from pytest import main ModuleNotFoundError: No module named 'pytest'
    • 再次更改为$(which py.test) functions/**/test/*_test.py,现在错误/bin/sh: 1: functions/folder_a/test/main_test.py: Permission denied
    • 你的requirements.txt文件中有pytest吗?好像没有安装。
    • 是的,ls -R 表明它已正确安装。
    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2016-05-26
    • 1970-01-01
    相关资源
    最近更新 更多