Skip to content

Commit

Permalink
Migrate to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Nov 4, 2024
2 parents 83b8a08 + 1f7016c commit 53eafdc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci-sage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pip
pip install -r requirements.txt
- name: Build and check
run: |
make -j4 check
Expand Down Expand Up @@ -196,7 +197,8 @@ jobs:
- name: Install dependencies
run: |
brew install autoconf
python -m pip install --upgrade pip
pip install --upgrade pip
pip install -r requirements.txt
- name: Build and check
# Work around https://github.com/sagemath/cysignals/issues/179
run: |
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
global-include README README.rst VERSION LICENSE
global-include Makefile configure configure.ac
global-include setup.py rundoctests.py testgdb.py *.pyx
global-include setup.py testgdb.py *.pyx
graft src
graft docs/source
prune build
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PYTHON = python3
PIP = $(PYTHON) -m pip -v
LS_R = ls -Ra1

DOCTEST = $(PYTHON) -B rundoctests.py
DOCTEST = $(PYTHON) -m pytest


#####################
Expand Down
42 changes: 42 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pathlib

from _pytest.nodes import Collector
from _pytest.doctest import DoctestModule

collect_ignore = ["src/scripts/cysignals-CSI-helper.py"]


def pytest_collect_file(
file_path: pathlib.Path,
parent: Collector,
) -> DoctestModule | None:
"""Collect doctests in cython files and run them as test modules."""
config = parent.config
if file_path.suffix == ".pyx":
if config.option.doctestmodules:
return DoctestModule.from_parent(parent, path=file_path)
return None


# Need to import cysignals to initialize it
import cysignals
try:
import cysignals.alarm
except ImportError:
pass
try:
import cysignals.signals
except ImportError:
pass
try:
import cysignals.pselect
except ImportError:
pass
try:
import cysignals.pysignals
except ImportError:
pass
try:
import cysignals.tests
except ImportError:
pass
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[build-system]
requires = ['setuptools', 'Cython>=0.28']
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
addopts = "--doctest-modules --import-mode importlib"
norecursedirs = "builddir docs"
timeout = 30
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ wheel
Cython
Sphinx
flake8
pytest
pytest-timeout

0 comments on commit 53eafdc

Please sign in to comment.