Reputation: 1182
I would like Google Cloud Build to run the unit test I have in my python project after pushing the changes.
I am able to configure the step that runs the test, but I am not sure how to input the directory the holds the test and if I just put .
then it run 0 test
my project structure is: - project_name - package_name - test - sample_test.py
This is my cloudbuild.yaml
configuration:
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
The above fails with this message:
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
And if I replace the folder with just .
then it runs but does not discover any tests.
For copying the code to gs buckets, we use gsutil and then ./package_name copies the package to the bucket
Locally this of course works
How can I understand what is the correct folder structure for my tests to run? Thanks!
Upvotes: 5
Views: 3914
Reputation: 3913
appengine
container? Why not just use an official Python container - name: python:3.7
?
Steps run as Docker containers, and I see no reason to run Docker in docker when you want to run docker container.
Try this:steps:
- name: python:3.7
args: ["python","-m","unittest","discover","--verbose","-s","./package_name/test/","-p","*_test.py"]
id: unittest
__init__.py
file in the directory ./package_name/test
? The message directory is not importable
usually means that this directory is not a Python package because of missing __init__.py
file.Upvotes: 6