Skip to content

Improve pytest with custom markers and run smoke and unit first #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

Python template with some awesome tools to quickstart a Python project with the industry best practices.
It includes automatic generation of API documentation, tests using PyTest, code coverage,
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.
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.

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

Expand Down Expand Up @@ -90,12 +90,13 @@ This Project depends on the following projects.
cookiecutter https://github.com/nullhack/python-project-template
# move into your newly created project folder
```
2. Install UV and Taskipy
2. Install uv and Taskipy
```sh
pip install --user --upgrade uv taskipy
pip install --user --upgrade uv
```
3. Let Taskipy do it's magic
```sh
uv venv
uv pip install .[dev]
uv task test
uv task run
Expand Down
5 changes: 3 additions & 2 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ Some useful examples of how this project can be used:

* Install requirements
```sh
uv run task '.[dev]'
uv venv
uv pip install '.[dev]'
```

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

* Run the project
```sh
uv run main.py
uv run task run
```

* Generate API documentation
Expand Down
39 changes: 30 additions & 9 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,23 @@ pydocstyle.convention = "google"

[tool.pytest.ini_options]
minversion = "6.0"
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"unit",
"integration",
"system",
"acceptance",
"regression",
"smoke",
"sanity",
"performance",
"security",
"performance",
]
addopts = """
--maxfail=1 \
--color=yes \
--cov={{cookiecutter.package_name}} \
--html=docs/pytest_report.html \
--self-contained-html \
--cov-fail-under={{cookiecutter.minimum_coverage}} \
--cov-report term-missing \
--cov-report html:docs/cov-report \
--doctest-modules \
--cov-config=pyproject.toml"""
"""
testpaths = [
"tests",
"{{cookiecutter.package_name}}"
Expand All @@ -110,7 +116,22 @@ exclude_lines = [

[tool.taskipy.tasks]
run = "python -m {{cookiecutter.package_name}}.{{cookiecutter.module_name}}"
test = "pytest"
test-report = """\
pytest \
--cov-config=pyproject.toml \
--doctest-modules \
--cov-fail-under=90 \
--cov-report=term-missing \
--cov-report=html:docs/cov-report \
--html=docs/pytest_report.html \
--self-contained-html\
"""
test = """\
python -c "import subprocess, sys; print('Running Smoke Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'smoke']).returncode in (0,5) else 1)" && \
python -c "import subprocess, sys; print('Running Unit Tests...'); sys.exit(0 if subprocess.run(['pytest', '-m', 'unit']).returncode in (0,5) else 1)" && \
python -c "print('Running Tests...');" && \
task test-report\
"""
ruff-check = "ruff check **/*.py --fix"
ruff-format = "ruff format **/*.py"
lint = "task ruff-check && task ruff-format"
Expand Down