Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 7217db8

Browse files
author
Release Manager
committed
Trac #31003: Add minimal pytest configuration
Add a minimal pytest configuration, so that calling `pytest` from `src` passes without any errors (and without finding any tests for the moment). This is a preparation for future usages of pytest, such as #30362 or #30738, and is in the general spirit of #28936 (since pytest is perhaps ''the'' testing framework for python). For example, one could imagine using `pytest doctest_modules` to run all sage doctests as well. URL: https://trac.sagemath.org/31003 Reported by: gh-tobiasdiez Ticket author(s): Tobias Diez Reviewer(s): Matthias Koeppe
2 parents c462eeb + 462f071 commit 7217db8

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# pyright: strict
2+
3+
"""Configuration and fixtures for pytest.
4+
5+
This file configures pytest and provides some global fixtures.
6+
See https://docs.pytest.org/en/latest/index.html for more details.
7+
8+
At the moment, Sage is not yet using any tests based on pytest.
9+
"""
10+
11+
from __future__ import annotations
12+
from typing import Any
13+
import pytest
14+
15+
# Ignore a few test files that are (not yet) using pytest
16+
collect_ignore = [
17+
"sage/misc/nested_class_test.py",
18+
"sage/repl/rich_output/backend_test.py",
19+
"sage/tests/deprecation_test.py"
20+
]
21+
22+
23+
@pytest.fixture(autouse=True)
24+
def add_imports(doctest_namespace: dict[str, Any]):
25+
"""
26+
Add global imports for doctests.
27+
28+
See `pytest documentation <https://docs.pytest.org/en/stable/doctest.html#doctest-namespace-fixture>`.
29+
"""
30+
import sage.all # type: ignore # implicitly used below by calling locals()
31+
doctest_namespace.update(**locals())

src/doc/en/developer/tools.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88
Additional development and testing tools
99
========================================
1010

11+
Pytest
12+
===============================
13+
`Pytest <https://docs.pytest.org/en/stable/>`_ is a testing framework.
14+
At the moment, Sage is not yet using any tests based on pytest.
15+
16+
*Installation:* ``pip install -U pytest``, see `documentation <https://docs.pytest.org/en/stable/getting-started.html#installation-and-getting-started>`__ for details.
17+
*Usage:*
18+
- Manual: Run ``pytest path/to/the/test_file.py`` or ``pytest`` to run all tests (from a virtual environment with Sage installed)
19+
- VS Code: Install the `Python <https://marketplace.visualstudio.com/items?itemName=ms-python.python>`_ extension and follow the `offical VS Code documentation <https://code.visualstudio.com/docs/python/testing>`__.
20+
*Configuration:* ``conftest.py`` in the source folder
21+
*Documentation:* https://docs.pytest.org/en/stable/index.html
22+
1123
Pyright
1224
===============================
13-
`Pyright <https://github.com/microsoft/pyright>` is static type checker.
25+
`Pyright <https://github.com/microsoft/pyright>`_ is static type checker.
1426

15-
*Installation:* ``npm install -g pyright``, see `documentation <https://github.com/microsoft/pyright#installation>`_ for details.
27+
*Installation:* ``npm install -g pyright``, see `documentation <https://github.com/microsoft/pyright#installation>`__ for details.
1628
*Usage:*
1729
- Manual: Run ``pyright path/to/the/file.py``
18-
- VS Code: Install the `Pylance <https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance>`_ extension.
30+
- VS Code: Install the `Pylance <https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance>`__ extension.
1931
*Configuration:* ``pyrightconfig.json`` in the root
2032
*Note*: Currently, only the manifolds package is checked. Further packages can be added in the ``pyrightconfig.json`` file.
2133
*Documentation:* https://github.com/microsoft/pyright#documentation
@@ -27,7 +39,7 @@ Pycodestyle
2739
*Installation:* ``pip install -U pycodestyle --user``
2840
*Usage:*
2941
- Manual: Run ``pycodestyle path/to/the/file.py``
30-
- VS Code: Activate by adding the setting ``"python.linting.pycodestyleEnabled": true``, see `official VS Code documentation <https://code.visualstudio.com/docs/python/linting>`_ for details.
42+
- VS Code: Activate by adding the setting ``"python.linting.pycodestyleEnabled": true``, see `official VS Code documentation <https://code.visualstudio.com/docs/python/linting>`__ for details.
3143
*Configuration:* ``[pycodestyle]`` block in ``src/tox.ini``
3244
*Documentation:* https://pycodestyle.pycqa.org/en/latest/index.html
3345

src/tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,6 @@ commands = codespell \
115115
--dictionary={toxinidir}/.codespell-dictionary.txt \
116116
--ignore-words={toxinidir}/.codespell-ignore.txt \
117117
{posargs:{toxinidir}/sage/}
118+
119+
[pytest]
120+
python_files = *_test.py

0 commit comments

Comments
 (0)