Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 445
user1222324562 Avatar asked Oct 16 '22 14:10

user1222324562


1 Answers

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.

like image 163
Dustin Ingram Avatar answered Nov 03 '22 19:11

Dustin Ingram