Add pytest support

This commit is contained in:
Eloi Torrents 2025-09-22 17:38:33 +02:00
parent 4d7c1a1d12
commit 9b43f5c9b2
3 changed files with 15 additions and 2 deletions

View File

@ -10,12 +10,16 @@ A lightweight template that shows how to structure a SageMath package and ship a
- `just prepare` create the Sage-aware virtualenv and install the package editable
- `just run` execute the elliptic curve demo inside that virtualenv
- `just test` run the unit tests with Sage's Python
- `just pytest` run the unit tests through pytest to get pytest-style output and plugins
## Running tests
Use Sage's Python so Sage-specific imports resolve correctly when you run the bundled unittest suite:
Use Sage's Python so Sage-specific imports resolve correctly when you run the bundled unittest suite. The tests ship as `unittest.TestCase` classes, so you can call either driver:
```bash
sage -python -m unittest discover -s tests -t .
# or, for pytest reporting
sage -python -m pytest
```
## Project layout

View File

@ -3,7 +3,7 @@ SAGE_PY := "sage -python"
# Create the Sage-aware virtual environment and install this package editable.
prepare:
if [ ! -d .venv ]; then {{SAGE_PY}} -m venv --system-site-packages .venv; fi
.venv/bin/pip install --no-build-isolation -e .
.venv/bin/pip install --no-build-isolation -e ".[test]"
# Upgrade pip inside the managed virtual environment.
update: prepare
@ -16,3 +16,7 @@ run: prepare
# Execute the unit test suite.
test: prepare
.venv/bin/python -m unittest discover -s tests -t .
# Execute the test suite via pytest so pytest plugins and reporting work out of the box.
pytest: prepare
.venv/bin/python -m pytest

View File

@ -28,6 +28,9 @@ Documentation = "https://git.32bit.cafe/eloitor/SageMath_package_template"
Source = "https://git.32bit.cafe/eloitor/SageMath_package_template"
Issues = "https://git.32bit.cafe/eloitor/SageMath_package_template/issues"
[project.optional-dependencies]
test = ["pytest>=8.2"]
[tool.setuptools]
include-package-data = true
@ -35,3 +38,5 @@ include-package-data = true
where = ["."]
include = ["demo_package*"]
[tool.pytest.ini_options]
testpaths = ["tests"]