From e41f10d650adcfbfde1f7445fedad2cc13b1674e Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 25 Oct 2025 10:01:12 +0100 Subject: [PATCH 1/2] tests: Don't scan build/scratch directories for tests This was interfering with running tests locally, pytest - scanned .git/ & tried to parse content as Python source - scanned build/ and found duplicates of e.g. wasmtime/_config.py This restores the relavant default globs for norecursedirs, that were previously overridden. https://docs.pytest.org/en/7.1.x/reference/reference.html#confval-norecursedirs E.g. ``` __________ ERROR collecting .git/logs/refs/remotes/origin/issue231-src-dist-version_suffix_in_setup.py __________ .venv/lib/python3.9/site-packages/_pytest/python.py:498: in importtestmodule mod = import_path( .venv/lib/python3.9/site-packages/_pytest/pathlib.py:587: in import_path importlib.import_module(module_name) ../../.local/share/uv/python/cpython-3.9.23-macos-aarch64-none/lib/python3.9/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) :1030: in _gcd_import ??? :1007: in _find_and_load ??? :986: in _find_and_load_unlocked ??? :680: in _load_unlocked ??? :846: in exec_module ??? :983: in get_code ??? :913: in source_to_code ??? :228: in _call_with_frames_removed ??? E File "/Users/alex/src/wasmtime-py/.git/logs/refs/remotes/origin/issue231-src-dist-version_suffix_in_setup.py", line 1 E 0000000000000000000000000000000000000000 61c83b67cf1f3f1bd2c2f052f15ac8236b21eb51 Alex Willmer 1749727258 +0100 update by push E ^ E SyntaxError: invalid syntax ``` ``` __________ ERROR collecting src/wasmtime/bindgen/generated/imports/stderr.py __________ import file mismatch: imported module 'wasmtime.bindgen.generated.imports.stderr' has this __file__ attribute: /Users/alex/src/wasmtime-py/build/lib/wasmtime/bindgen/generated/imports/stderr.py which is not the same as the test file we want to collect: /Users/alex/src/wasmtime-py/src/wasmtime/bindgen/generated/imports/stderr.py HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules ``` --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytest.ini b/pytest.ini index 11f60732..8eb7b007 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,9 @@ [pytest] addopts = --doctest-modules --mypy --ignore-glob=tests/bindgen/*/app.py norecursedirs = + .* + *.egg + build ci/_custom_build + dist tests/bindgen/generated/* From 3281aa3b1d1c3a3dbe6766fdda1b7051997a5398 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 25 Oct 2025 10:30:13 +0100 Subject: [PATCH 2/2] tests: Add noxfile.py to run tests locally across Python versions Nox is a Python CLI tool for running tests or other build/project management tasks. It's invoked as - `nox` or `python3 -m nox` - run every session defined in noxfile.py - `nox --list` - list sessions defined - `nox -s ` - Run a particular session - `nox -p - Run sessions the use the given python version(s) If desired checks such as MyPy or style can also be included. See https://nox.thea.codes/en/stable/index.html --- MANIFEST.in | 1 + noxfile.py | 18 ++++++++++++++++++ pytest.ini | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 noxfile.py diff --git a/MANIFEST.in b/MANIFEST.in index 16645f08..cc13c0a2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -20,6 +20,7 @@ recursive-exclude wasmtime/bindgen/generated *.py *.wasm include .flake8 include CONTRIBUTING.md include mypy.ini +include noxfile.py include pytest.ini include VERSION diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..1c952822 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,18 @@ +import nox + +PYPROJECT = nox.project.load_toml('pyproject.toml') + +PYTHONS = [ + # Reads versions from Trove classifiers + *nox.project.python_versions(PYPROJECT), +] + +# Prefer uv to create virtual environments, fall back to virtualenv. +# Overriden by $NOX_DEFAULT_VENV_BACKEND=... or nox --default-venv-backend ... +# https://nox.thea.codes/en/stable/usage.html#changing-the-sessions-default-backend +nox.options.default_venv_backend = 'uv|virtualenv' + +@nox.session(python=PYTHONS, tags=["test"]) +def tests(session): + session.install('.[testing]') + session.run('coverage', 'run', '-m', 'pytest') diff --git a/pytest.ini b/pytest.ini index 8eb7b007..7e11eb77 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,9 @@ [pytest] -addopts = --doctest-modules --mypy --ignore-glob=tests/bindgen/*/app.py +addopts = + --doctest-modules + --ignore-glob=tests/bindgen/*/app.py + --ignore-glob=noxfile.py + --mypy norecursedirs = .* *.egg