Skip to content

Commit 4cacc93

Browse files
authored
Improve pytest with custom markers and run smoke and unit first (#8)
* Removing taskipy as required installation (it is installed with [dev]) * Update README.md * Update README.md * Update README.md * Improving pytest with markers and run smoke and unit tests before others
1 parent 366598e commit 4cacc93

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
Python template with some awesome tools to quickstart a Python project with the industry best practices.
6464
It includes automatic generation of API documentation, tests using PyTest, code coverage,
65-
ruff linting to enforce standardized Python coding and formatting, virtual environments using UV, workflow automation using Taskipy and a space optimized Dockerfile to kickstart your project and run tests using the power of Docker containers.
65+
ruff linting to enforce standardized Python coding and formatting, virtual environments using uv, workflow automation using Taskipy and a space optimized Dockerfile to kickstart your project and run tests using the power of Docker containers.
6666

6767
You only need to install [Cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/usage.html)!
6868

@@ -90,12 +90,13 @@ This Project depends on the following projects.
9090
cookiecutter https://github.com/nullhack/python-project-template
9191
# move into your newly created project folder
9292
```
93-
2. Install UV and Taskipy
93+
2. Install uv and Taskipy
9494
```sh
95-
pip install --user --upgrade uv taskipy
95+
pip install --user --upgrade uv
9696
```
9797
3. Let Taskipy do it's magic
9898
```sh
99+
uv venv
99100
uv pip install .[dev]
100101
uv task test
101102
uv task run

{{cookiecutter.project_slug}}/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ Some useful examples of how this project can be used:
113113

114114
* Install requirements
115115
```sh
116-
uv run task '.[dev]'
116+
uv venv
117+
uv pip install '.[dev]'
117118
```
118119

119120
* Run tests
@@ -123,7 +124,7 @@ Some useful examples of how this project can be used:
123124

124125
* Run the project
125126
```sh
126-
uv run main.py
127+
uv run task run
127128
```
128129

129130
* Generate API documentation

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,23 @@ pydocstyle.convention = "google"
7676

7777
[tool.pytest.ini_options]
7878
minversion = "6.0"
79+
markers = [
80+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
81+
"unit",
82+
"integration",
83+
"system",
84+
"acceptance",
85+
"regression",
86+
"smoke",
87+
"sanity",
88+
"performance",
89+
"security",
90+
"performance",
91+
]
7992
addopts = """
8093
--maxfail=1 \
8194
--color=yes \
82-
--cov={{cookiecutter.package_name}} \
83-
--html=docs/pytest_report.html \
84-
--self-contained-html \
85-
--cov-fail-under={{cookiecutter.minimum_coverage}} \
86-
--cov-report term-missing \
87-
--cov-report html:docs/cov-report \
88-
--doctest-modules \
89-
--cov-config=pyproject.toml"""
95+
"""
9096
testpaths = [
9197
"tests",
9298
"{{cookiecutter.package_name}}"
@@ -110,7 +116,22 @@ exclude_lines = [
110116

111117
[tool.taskipy.tasks]
112118
run = "python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}"
113-
test = "pytest"
119+
test-report = """\
120+
pytest \
121+
--cov-config=pyproject.toml \
122+
--doctest-modules \
123+
--cov-fail-under=90 \
124+
--cov-report=term-missing \
125+
--cov-report=html:docs/cov-report \
126+
--html=docs/pytest_report.html \
127+
--self-contained-html\
128+
"""
129+
test = """\
130+
python -c "import subprocess, sys; print('Running Smoke Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'smoke']).returncode in (0,5) else 1)" && \
131+
python -c "import subprocess, sys; print('Running Unit Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'unit']).returncode in (0,5) else 1)" && \
132+
python -c "print('Running Tests...');" && \
133+
task test-report\
134+
"""
114135
ruff-check = "ruff check **/*.py --fix"
115136
ruff-format = "ruff format **/*.py"
116137
lint = "task ruff-check && task ruff-format"

0 commit comments

Comments
 (0)