PyTest (without Docker Compose)¶
Run pytest for your application, inside a container.
Prerequisites¶
- The tests must be included in the image (via Dockerfile).
- PyTest must be installed for the dockerfile USER.
Note: this workflow also injects dotenv vars present in your Github environment called
test
(or set byinputs.environment
). See the test_compose docs for more details.
Inputs¶
INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
---|---|---|---|---|
build_context | string | false | "." |
Root directory to start the build from. |
build_dockerfile | string | false | "Dockerfile" |
Name of dockerfile, relative to context dir. |
build_target | string | false | "ci" |
The target to built to (default to ci stage). |
cache_image | boolean | false | true |
Cache the built image, for the next run. Default true. |
environment | string | false | "test" |
The environment to use for testing. |
example_env_file_path | string | false | ".env.example" |
Path to example dotenv file to substitute variables for. |
extra_build_args | string | false | Space separated list of build args to use for the image. |
|
image_name | string | true | The image root name, without tag. E.g. 'ghcr.io/[dollar]{{ github.repository }}' |
|
tag_override | string | false | An override for the build image tag. Must include tests and have PyTest installed |
Outputs¶
No outputs.
Secrets¶
No secrets.
Example Usage¶
Running on push and PR:
name: pytest
on:
push:
branches: [main]
# Run tests on PR, prior to merge to main & development
pull_request:
branches: [main]
# Allow manual trigger (workflow_dispatch)
workflow_dispatch:
jobs:
pytest:
uses: hotosm/gh-workflows/.github/workflows/test_pytest.yml@main
with:
image_name: ghcr.io/${{ github.repository }}
extra_build_args: |
COMMIT_REF=${{ github.sha }}
tag_override: ${{ github.event_name == 'push' && 'ci' || '' }}
This includes a tag_override, so that in a pull_request event
the image is tagged with the PR number, but during a push
event the image is tagged as ci
(to not confuse it with releases).
Last update:
July 27, 2024