From 9b43f5c9b25330af517954e55c8b04667553a6fb Mon Sep 17 00:00:00 2001 From: Eloi Torrents Date: Mon, 22 Sep 2025 17:38:33 +0200 Subject: [PATCH] Add pytest support --- README.md | 6 +++++- justfile | 6 +++++- pyproject.toml | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77a729c..ac38cef 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/justfile b/justfile index b81b107..26223bb 100644 --- a/justfile +++ b/justfile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index b44fb6a..f5fa014 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]