Skip to content

Commit 56aa100

Browse files
authored
chore(tests): allow test customization via cli (#44)
1 parent 3ce8256 commit 56aa100

6 files changed

Lines changed: 24 additions & 4 deletions

File tree

Taskfile.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,19 @@ tasks:
7676

7777
unit-test:
7878
desc: Run the unit tests
79+
vars:
80+
# If CLI_ARGS are set, append them as an "and" after the -m unit
81+
MARK_EXPR: unit{{if .CLI_ARGS}} and {{.CLI_ARGS}}{{end}}
7982
cmds:
80-
- '{{.RUN_SCRIPT}} pytest --keep-baked-projects -m unit tests/'
83+
- '{{.RUN_SCRIPT}} pytest --keep-baked-projects -m "{{.MARK_EXPR}}" tests/'
8184

8285
integration-test:
8386
desc: Run the integration tests
87+
vars:
88+
# If CLI_ARGS are set, append them as an "and" after the -m integration
89+
MARK_EXPR: integration{{if .CLI_ARGS}} and {{.CLI_ARGS}}{{end}}
8490
cmds:
85-
- '{{.RUN_SCRIPT}} pytest --keep-baked-projects -m integration tests/'
91+
- '{{.RUN_SCRIPT}} pytest --keep-baked-projects -m "{{.MARK_EXPR}}" tests/'
8692

8793
update:
8894
desc: Update the project dev and runtime dependencies

docs/testing.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ task unit-test # Run unit tests only
2020
task integration-test # Run integration tests only
2121
```
2222

23+
If you'd like to exclude tests that are marked a certain way, you can pass additional details to the above tasks, for instance:
24+
25+
```bash
26+
task test -- "not slow" # Skip slow tests
27+
```
28+
2329
### What Template Tests Cover
2430

2531
- **Generation Validation**: Tests with various input combinations to ensure valid project generation

tests/test_cookiecutter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def test_autofix_hook(cookies, context):
212212

213213

214214
@pytest.mark.integration
215+
@pytest.mark.slow
215216
def test_default_project(cookies):
216217
"""
217218
Test a default project thoroughly

{{cookiecutter.project_name|replace(" ", "")}}/.github/CONTRIBUTING.md renamed to {{cookiecutter.project_name|replace(" ", "")}}/.github/CODE_OF_CONDUCT.md

File renamed without changes.

{{cookiecutter.project_name|replace(" ", "")}}/Taskfile.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,23 @@ tasks:
164164
unit-test:
165165
desc: Run the project unit tests
166166
deps: ["coverage-erase"]
167+
vars:
168+
# If CLI_ARGS are set, append them as an "and" after the -m unit
169+
MARK_EXPR: unit{{ '{{if .CLI_ARGS}}' }} and {{ '{{.CLI_ARGS}}{{end}}' }}
167170
cmds:
168-
- '{{ '{{.RUN_SCRIPT}}' }} pytest -m unit tests/'
171+
- '{{ '{{.RUN_SCRIPT}}' }} pytest -m "{{ '{{.MARK_EXPR}}' }}" tests/'
169172

170173
integration-test:
171174
desc: Run the project integration tests
172175
deps: ["coverage-erase"]
176+
vars:
177+
# If CLI_ARGS are set, append them as an "and" after the -m integration
178+
MARK_EXPR: integration{{ '{{if .CLI_ARGS}}' }} and {{ '{{.CLI_ARGS}}{{end}}' }}
173179
status:
174180
# Only run integration tests when the PLATFORM is set to all or the same platform as we're running on
175181
- '{{ '{{if or (eq .PLATFORM "all") (eq .PLATFORM .LOCAL_PLATFORM) (not .PLATFORM)}}' }}exit 1{{ '{{else}}' }}exit 0{{ '{{end}}' }}'
176182
cmds:
177-
- '{{ '{{.RUN_SCRIPT}}' }} pytest -m integration tests/'
183+
- '{{ '{{.RUN_SCRIPT}}' }} pytest -m "{{ '{{.MARK_EXPR}}' }}" tests/'
178184

179185
update:
180186
desc: Update the project dev and runtime dependencies

{{cookiecutter.project_name|replace(" ", "")}}/tests/test_integration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
@pytest.mark.integration
16+
@pytest.mark.slow
1617
def test_project_tasks():
1718
"""
1819
Test the project's task runner commands work together properly.

0 commit comments

Comments
 (0)