user1222324562
user1222324562

Reputation: 1075

Run pytest in Google Build cloudbuild.yaml to determine if build passes or not

My project structure is as follows:

cloudbuild.yaml
requirements.txt
functions/
    folder_a/
        test/
            main_test.py
        main.py

My 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']

What builder do I use to run pytest? I just installed it using the previous install step. Should I use that same docker image? How do I stop my build from passing until pytest successfully finishes all tests?

Upvotes: 6

Views: 4053

Answers (1)

Dustin Ingram
Dustin Ingram

Reputation: 21520

Each step runs in a separate container, so you should do it all in one step:

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'

See "GitOps-style continuous delivery with Cloud Build" for more details.

Upvotes: 4

Related Questions