Add pytest support
This commit is contained in:
parent
4d7c1a1d12
commit
9b43f5c9b2
@ -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 prepare` – create the Sage-aware virtualenv and install the package editable
|
||||||
- `just run` – execute the elliptic curve demo inside that virtualenv
|
- `just run` – execute the elliptic curve demo inside that virtualenv
|
||||||
- `just test` – run the unit tests with Sage's Python
|
- `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
|
## 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
|
```bash
|
||||||
sage -python -m unittest discover -s tests -t .
|
sage -python -m unittest discover -s tests -t .
|
||||||
|
|
||||||
|
# or, for pytest reporting
|
||||||
|
sage -python -m pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Project layout
|
## Project layout
|
||||||
|
6
justfile
6
justfile
@ -3,7 +3,7 @@ SAGE_PY := "sage -python"
|
|||||||
# Create the Sage-aware virtual environment and install this package editable.
|
# Create the Sage-aware virtual environment and install this package editable.
|
||||||
prepare:
|
prepare:
|
||||||
if [ ! -d .venv ]; then {{SAGE_PY}} -m venv --system-site-packages .venv; fi
|
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.
|
# Upgrade pip inside the managed virtual environment.
|
||||||
update: prepare
|
update: prepare
|
||||||
@ -16,3 +16,7 @@ run: prepare
|
|||||||
# Execute the unit test suite.
|
# Execute the unit test suite.
|
||||||
test: prepare
|
test: prepare
|
||||||
.venv/bin/python -m unittest discover -s tests -t .
|
.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
|
||||||
|
@ -28,6 +28,9 @@ Documentation = "https://git.32bit.cafe/eloitor/SageMath_package_template"
|
|||||||
Source = "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"
|
Issues = "https://git.32bit.cafe/eloitor/SageMath_package_template/issues"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
test = ["pytest>=8.2"]
|
||||||
|
|
||||||
[tool.setuptools]
|
[tool.setuptools]
|
||||||
include-package-data = true
|
include-package-data = true
|
||||||
|
|
||||||
@ -35,3 +38,5 @@ include-package-data = true
|
|||||||
where = ["."]
|
where = ["."]
|
||||||
include = ["demo_package*"]
|
include = ["demo_package*"]
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
testpaths = ["tests"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user