From e5b7e15d8293854c4eda9f9918450a85f94cef14 Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Wed, 23 Aug 2023 15:15:25 +0200 Subject: [PATCH] simplify pytest template --- templates/python/testing/pytest/README.md | 18 ++++++++++-------- templates/python/testing/pytest/pytest.yml | 5 +++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/templates/python/testing/pytest/README.md b/templates/python/testing/pytest/README.md index a46b643..4e9065b 100644 --- a/templates/python/testing/pytest/README.md +++ b/templates/python/testing/pytest/README.md @@ -10,15 +10,16 @@ automation, modular fixtures, parameterized testing, and many other features. 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). + the [job customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization). ## Variables -| Name | Description | Default | -|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------| -| `PROJECT_PATH` | The path to the project root directory. | `"."` | -| `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"` | -| `PYTHON_SETUP` | Bash commands to setup your python environment. Default rely on `pyproject.toml` to install project and test dependencies. | `"pip install .[TESTS]"` | +| Name | Description | Default | +|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------| +| `PROJECT_PATH` | The path to the project root directory. | `"."` | +| `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"` | +| `PYTHON_SETUP` | Bash commands to setup your python environment. Default rely on `pyproject.toml` to install project and test dependencies. | `"pip install .[TESTS]"` | +| `PYTEST_RUN_CMD` | Bash command to run pytest. | `"pytest ${PROJECT_PATH}"` | ## Global Configuration of pytest @@ -28,7 +29,8 @@ about [pytest configuration](https://docs.pytest.org/en/stable/customize.html) f ## Multiple pytest Jobs in the same pipeline -You can run this pytest job multiple times in the same pipeline (e.g. to test multiple python version +You can run this pytest job multiple times in the same pipeline (e.g. to test multiple python +version or different namespaces) using extends GitLab keyword. ```yaml @@ -36,7 +38,7 @@ stages: - test include: - - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/pytest@1.0.0.yaml' + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/pytest@1.0.0.yaml' # Compatibility tests pytest_3.10: diff --git a/templates/python/testing/pytest/pytest.yml b/templates/python/testing/pytest/pytest.yml index d033176..d646bad 100644 --- a/templates/python/testing/pytest/pytest.yml +++ b/templates/python/testing/pytest/pytest.yml @@ -7,10 +7,11 @@ pytest: variables: IMAGE_TAG: !reference [.python_install, variables, IMAGE_TAG] PROJECT_PATH: "." - PYTHON_SETUP: "pip install ${PROJECT_PATH}[TESTS]" + PYTHON_SETUP: "pip install -r ${PROJECT_PATH}/requirements.txt" + PYTEST_RUN_CMD: "pytest ${PROJECT_PATH}" script: - !reference [.python_install, script] - - pytest ${PROJECT_PATH} + - ${PYTEST_RUN_CMD} only: changes: - ${PROJECT_PATH}/**/*.py -- GitLab