From d55fbb42c1236d0f3c331d86d287658e91e0e0f2 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Thu, 29 Aug 2024 16:01:10 +0200 Subject: [PATCH] Remove tests from minimum profile Introduces a question AddLocalTests to control the existence of the tests folder. If the user selects 'GitHub Actions -> Build' or 'Code analysis (using SonarCloud)' then this option is also selected. Related to #594 --- CHANGELOG.md | 1 + copier/questions/features_code_quality.yml | 9 ++++++++- template/project_setup.md.jinja | 2 ++ template/pyproject.toml.jinja | 8 ++++++++ ...if AddContributing %}CONTRIBUTING.md{% endif %}.jinja | 2 ++ .../__init__.py | 0 .../test_my_module.py.jinja | 0 7 files changed, 21 insertions(+), 1 deletion(-) rename template/{tests => {% if AddLocalTests %}tests{% endif %}}/__init__.py (100%) rename template/{tests => {% if AddLocalTests %}tests{% endif %}}/test_my_module.py.jinja (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index fae58d58..e97f3abe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Make SonarCloud optional [#515](https://github.com/NLeSC/python-template/pull/515) * Make citation optional [#471](https://github.com/NLeSC/python-template/pull/471) * Make online documentation optional [#476](https://github.com/NLeSC/python-template/pull/476) +* Make local test optional [#594](https://github.com/NLeSC/python-template/pull/594) ### Changed * Update the user documentation (README.md) of the template [#575](https://github.com/NLeSC/python-template/pull/623) diff --git a/copier/questions/features_code_quality.yml b/copier/questions/features_code_quality.yml index ea29397f..b6e98791 100644 --- a/copier/questions/features_code_quality.yml +++ b/copier/questions/features_code_quality.yml @@ -7,13 +7,16 @@ SelectCodeQualityFeatures: type: yaml default: |- {% if template_profile == 'recommended' %} - [SelectGitHubActions_flag, AddLinting_flag, AddSonarCloud_flag, AddEditorConfig_flag] + [AddLocalTests_flag, SelectGitHubActions_flag, AddLinting_flag, AddSonarCloud_flag, AddEditorConfig_flag] {%- else -%} [] {%- endif %} help: Select code quality features multiselect: true choices: + Local tests: + value: AddLocalTests_flag + # validator: "{% if something != 'AnotherThing' %}BlaBla{% endif %}" GitHub Actions (selection on the next menu): value: SelectGitHubActions_flag # validator: "{% if something != 'AnotherThing' %}BlaBla{% endif %}" @@ -56,6 +59,10 @@ SelectGitHubActions: # computed features +AddLocalTests: + type: bool + default: "{{ 'AddLocalTests_flag' in SelectCodeQualityFeatures or 'AddGitHubActionBuild_flag' in SelectGitHubActions or 'AddSonarCloud_flag' in SelectCodeQualityFeatures }}" + when: false AddGitHubActionBuild: type: bool default: "{{ 'AddGitHubActionBuild_flag' in SelectGitHubActions }}" diff --git a/template/project_setup.md.jinja b/template/project_setup.md.jinja index 6d4a4b46..4e3aff1d 100644 --- a/template/project_setup.md.jinja +++ b/template/project_setup.md.jinja @@ -35,6 +35,7 @@ You can distribute your code using PyPI. [The guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=building-and-packaging-code) can help you decide which tool to use for packaging. +{% if AddLocalTests -%} ## Testing and code coverage - Tests should be put in the `tests` folder. @@ -47,6 +48,7 @@ help you decide which tool to use for packaging. - The project uses [GitHub action workflows](https://docs.github.com/en/actions) to automatically run tests on GitHub infrastructure against multiple Python versions - Workflows can be found in [`.github/workflows`](.github/workflows/) - [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=testing) +{%- endif %} ## Documentation diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 0ec6f942..dd339db7 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -45,9 +45,11 @@ version = "{{ version }}" dev = [ "build", # build is not only used in publishing (below), but also in the template's test suite "bump-my-version", + {%- if AddLocalTests %} "coverage [toml]", "pytest", "pytest-cov", + {%- endif %} "ruff", "sphinx", "sphinx_rtd_theme", @@ -76,22 +78,28 @@ Changelog = "{{ repository_url }}/CHANGELOG.md" {% if AddOnlineDocumentation -%} ReadTheDocs = "https://{{ package_name }}.readthedocs.io" {% endif %} +{% if AddLocalTests -%} [tool.pytest.ini_options] testpaths = ["tests"] +{% endif %} +{% if AddLocalTests -%} [tool.coverage.run] branch = true source = ["src/{{ package_name }}"] command_line = "-m pytest" +{%- endif %} [tool.tox] legacy_tox_ini = """ [tox] envlist = py38,py39,py310,py311,py312 skip_missing_interpreters = true +{% if AddLocalTests -%} [testenv] commands = pytest extras = dev +{%- endif %} """ [tool.ruff] diff --git a/template/{% if AddContributing %}CONTRIBUTING.md{% endif %}.jinja b/template/{% if AddContributing %}CONTRIBUTING.md{% endif %}.jinja index 03296187..a3a845f2 100644 --- a/template/{% if AddContributing %}CONTRIBUTING.md{% endif %}.jinja +++ b/template/{% if AddContributing %}CONTRIBUTING.md{% endif %}.jinja @@ -34,8 +34,10 @@ The sections below outline the steps in each case. {% if AddDevDoc -%} 1. install dependencies (see the [development documentation](README.dev.md#development_install)); {%- endif %} +{% if AddLocalTests -%} 1. make sure the existing tests still work by running ``pytest``; 1. add your own tests (if necessary); +{%- endif %} 1. update or expand the documentation; {% if AddChangeLog -%} 1. update the `CHANGELOG.md` file with your change; diff --git a/template/tests/__init__.py b/template/{% if AddLocalTests %}tests{% endif %}/__init__.py similarity index 100% rename from template/tests/__init__.py rename to template/{% if AddLocalTests %}tests{% endif %}/__init__.py diff --git a/template/tests/test_my_module.py.jinja b/template/{% if AddLocalTests %}tests{% endif %}/test_my_module.py.jinja similarity index 100% rename from template/tests/test_my_module.py.jinja rename to template/{% if AddLocalTests %}tests{% endif %}/test_my_module.py.jinja