From b2b0b4752fa3caeeee5a9957b073812c99b0d84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bosch?= Date: Mon, 9 Dec 2024 15:17:04 +0100 Subject: [PATCH] test: use nox for testing --- .github/workflows/tests.yml | 10 +++--- noxfile.py | 33 ++++++++++++++++++++ pyproject.toml | 61 +++---------------------------------- 3 files changed, 42 insertions(+), 62 deletions(-) create mode 100644 noxfile.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0c266a0..bae50ef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,11 +36,11 @@ jobs: tox tox-gh - - name: run tests suite - run: tox -vv - env: - TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} - CONDA_EXE: mamba + - name: setup nox + uses: wntrblm/nox@2024.10.09 + + - name: run nox (tests and build) + run: nox --force-python ${{ matrix.python-version }} - name: upload coverage reports to Codecov uses: codecov/codecov-action@v4 diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..8f7af08 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,33 @@ +"""Nox.""" + +import nox + +PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"] + + +@nox.session(python=PYTHON_VERSIONS, venv_backend="mamba|micromamba|conda") +def tests(session): + """Run tests with pytest, and collect coverage.""" + session.conda_install("gdal", channel=["conda-forge"]) + session.install(".[dev,test]") + + session.run( + "pytest", + "-s", + "--cov=pylandstats", + "--cov-append", + "--cov-report=xml", + "--cov-report=term-missing", + "tests", + ) + + +@nox.session(name="build", venv_backend="mamba|micromamba|conda") +def build(session): + """Build package and documentation.""" + session.conda_install("gdal", channel=["conda-forge"]) + session.install(".[doc,dev,test]") + + session.run("python", "-m", "build") + session.run("sphinx-build", "docs", "docs/_build") + session.run("twine", "check", "dist/*") diff --git a/pyproject.toml b/pyproject.toml index fa076ce..50d6ae9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ Repository = "https://github.com/martibosch/pylandstats" [project.optional-dependencies] test = ["coverage[toml]", "pytest", "pytest-cov", "ruff"] -dev = ["build", "commitizen", "pre-commit", "pip", "toml", "tox", "twine"] +dev = ["build", "commitizen", "nox", "pre-commit", "pip", "toml", "twine"] doc = ["m2r2", "pydata-sphinx-theme", "sphinx"] # [tool.setuptools] @@ -99,60 +99,7 @@ skip = "*-musllinux_i686" ignore-words-list = "te" skip = "CHANGELOG.md" -[tool.tox] -env_list = [ - "lint", - "py39", - "py310", - "py311", - "py312", - "py313", -] -requires = [ - "tox>=4.19", -] - -[tool.tox.gh.python] -"3.13" = ["3.13", "lint"] -"3.12" = ["3.12"] -"3.11" = ["3.11"] -"3.10" = ["3.10"] -"3.9" = ["3.9"] - -[tool.tox.env_run_base] -commands = [[ - "pytest", - "-s", - "--cov=pylandstats", - "--cov-append", - "--cov-report=xml", - "--cov-report", - "term-missing", - "tests", -]] -conda_deps = [ - "gdal>=3.3", -] -extras = [ - "test", -] -whitelist_externals = [ - "pytest", -] - -[tool.tox.env.lint] -commands = [[ - ["python", "-m", "build"], - ["sphinx-build", "docs", "docs/_build"], - ["twine", "check", "dist/*"], -]] -extras = [ - "dev", - "doc", - "test", -] -whitelist_externals = [ - "build", - "sphinx-build", - "twine", +[tool.pytest.ini_options] +addopts = [ + "--import-mode=importlib", ]