From eaed9ef5ac39fa72e1a8e2659c375467fff13d4f Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Mon, 10 Jul 2023 13:56:11 +0200 Subject: [PATCH] update pytest --- python/testing/pytest/README.md | 29 ++++++++++++++++++----------- python/testing/pytest/pytest.yml | 7 +++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/python/testing/pytest/README.md b/python/testing/pytest/README.md index b012f84..67e1917 100644 --- a/python/testing/pytest/README.md +++ b/python/testing/pytest/README.md @@ -4,7 +4,22 @@ Run [pytest](https://docs.pytest.org/en/latest/) on your Python code to ensure a Pytest is a popular framework for writing and executing tests in Python, and it supports test automation, modular fixtures, parameterized testing, and many other features. -### Global Configuration of pytest +## How to use it + +1. Configure the `pytest.ini` or `pyproject.toml` file in your repository's root directory with your + desired rules. +2. Include the pytest template in your CI/CD configuration (see quick use above). +3. If you need to customize the job, check + the [jobs customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization). + +## Variables + +| Name | Description | Default | +|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------| +| `PYTHON_SETUP` | Bash commands to setup your python environment. Default rely on `pyproject.toml` to install project and test dependencies. | `"pip install .[TESTS]"` | +| `IMAGE_TAG` | The default tag for the docker image. See [Python Docker Official Image](https://hub.docker.com/_/python) for supported tags and respective Dockerfile links | `"latest"` | + +## Global Configuration of pytest To add configuration to `pytest` that is shared with any other usage of pytest (such as manual runs, pre-commit, etc.), you can use the `pytest.ini` or `pyproject.toml` configuration files. Learn more @@ -34,14 +49,6 @@ testpaths = [ ] ``` -## How to use it - -1. Configure the `pytest.ini` or `pyproject.toml` file in your repository's root directory with your - desired rules. -2. Include the pytest template in your CI/CD configuration (see quick use above). -3. If you need to customize the job, check - the [jobs customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization). - ## Change the Python version By default, the template uses the latest Python version available in the image. If you need to @@ -49,10 +56,10 @@ change the Python version, you can override the docker image used in the templat ```yaml stages: - - test + - test include: - - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/pytest@latest.yaml' + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/pytest@latest.yaml' pytest: image: python:3.11 diff --git a/python/testing/pytest/pytest.yml b/python/testing/pytest/pytest.yml index 1dcc298..b4ca300 100644 --- a/python/testing/pytest/pytest.yml +++ b/python/testing/pytest/pytest.yml @@ -1,11 +1,14 @@ pytest: - image: python:latest + image: python:${IMAGE_TAG} stage: code_quality + variables: + PYTHON_SETUP: "pip install .[TESTS]" + IMAGE_TAG: "latest" script: - python --version # Debug - python -m venv venv --upgrade-deps || python -m venv venv # upgrade-deps is not supported before 3.9 - source venv/bin/activate - - pip install pytest + - ${PYTHON_SETUP} - pytest only: changes: -- GitLab