From: Trevor Woerner <twoerner@gmail.com>
To: yocto-patches@lists.yoctoproject.org
Subject: [wic][PATCH v3 03/10] tests: add the run-tests.sh wrapper
Date: Wed, 1 Jul 2026 03:40:23 -0400 [thread overview]
Message-ID: <20260701074030.1090807-4-twoerner@gmail.com> (raw)
In-Reply-To: <20260701074030.1090807-1-twoerner@gmail.com>
The suite is run with pytest, but invoking pytest directly has two
sharp edges: it must be run from the right directory for the pyproject
configuration to apply, and it happily runs against whatever Python
happens to be first on PATH, even one that cannot import wic. A run
against the wrong interpreter produces a misleading banner and, worse,
can silently exercise a different wic than the one in the checkout.
This commit adds tests/run-tests.sh, a thin wrapper that removes both
hazards:
- it locates the repository root from its own path and changes there
before running, so it works regardless of the caller's directory;
- it checks that the interpreter can import wic before handing off to
pytest, and fails loudly with the install command if it cannot;
- with no arguments it runs the whole suite under tests/; any
argument it does not recognise (a path, -k EXPR, -v, ...) is passed
straight through to pytest, and an explicit -- forwards everything
after it.
The interpreter can be overridden with the PYTHON environment variable
(default python3). -h/--help prints usage and exits.
The README Testing section gains the run-tests.sh invocation alongside
the install step.
AI-Generated: codex/claude-opus 4.7 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
changes in v3:
- no change in this revision.
changes in v2:
- v1 submitted the entire test suite as a single commit; v2 breaks
the work into a reviewable series, and this patch is one step of it.
---
README.md | 1 +
tests/run-tests.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
create mode 100755 tests/run-tests.sh
diff --git a/README.md b/README.md
index 497ebb1de0f0..e557eb435316 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,7 @@ extras pull in everything the suite needs:
```
pip install -e ".[tests]"
+tests/run-tests.sh
```
See [tests/docs/](tests/docs/) for how to run the suite and the
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
new file mode 100755
index 000000000000..9db6d50338d6
--- /dev/null
+++ b/tests/run-tests.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+#
+# Run the wic test suite.
+#
+# Thin wrapper around pytest that works from anywhere in the checkout:
+# it locates the repository root, makes sure the interpreter can import
+# wic, and then hands off to pytest.
+#
+# Needs the test extras: pip install -e ".[tests]"
+
+set -euo pipefail
+
+usage() {
+ cat <<'USAGE'
+Usage:
+ tests/run-tests.sh [pytest args]
+
+Options:
+ -h, --help show this help and exit
+
+Anything else is passed straight through to pytest (for example a
+path, -k EXPR, or -v). With no such argument the whole suite under
+tests/ is run.
+
+Examples:
+ tests/run-tests.sh # whole suite
+ tests/run-tests.sh -k filemap -v # pass args through to pytest
+ tests/run-tests.sh tests/unit # a single tier or file
+
+Needs the test extras: pip install -e ".[tests]"
+USAGE
+}
+
+REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+PY="${PYTHON:-python3}"
+
+pytest_args=()
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ --)
+ shift
+ pytest_args+=("$@")
+ break
+ ;;
+ *)
+ pytest_args+=("$1")
+ ;;
+ esac
+ shift
+done
+
+cd "$REPO_ROOT"
+
+# Make sure the interpreter that will run pytest can actually import wic.
+# The suites pass even without an install (each adds src/ to sys.path),
+# but the session banner and any install-dependent behaviour would be
+# wrong, so fail loudly instead of running against the wrong interpreter.
+if ! "$PY" -c "import wic" >/dev/null 2>&1; then
+ echo "error: '$PY' cannot import wic." >&2
+ echo " install wic with its test extras:" >&2
+ echo " $PY -m pip install -e \".[tests]\"" >&2
+ exit 1
+fi
+
+# Default target: the whole suite. Overridden if the caller passed a
+# path or -k/-m selector to pytest.
+if [ ${#pytest_args[@]} -eq 0 ]; then
+ pytest_args=("tests")
+fi
+
+exec "$PY" -m pytest "${pytest_args[@]}"
--
2.50.0.173.g8b6f19ccfc3a
next prev parent reply other threads:[~2026-07-01 7:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 7:40 [wic][PATCH v3 00/10] tests: standalone test-suite framework plus the first unit test Trevor Woerner
2026-07-01 7:40 ` [wic][PATCH v3 01/10] tests: add the standalone test-suite skeleton Trevor Woerner
2026-07-06 8:18 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 02/10] tests: add a session banner via conftest.py Trevor Woerner
2026-07-06 8:17 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` Trevor Woerner [this message]
2026-07-06 8:21 ` [yocto-patches] [wic][PATCH v3 03/10] tests: add the run-tests.sh wrapper Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 04/10] tests: add optional coverage reporting to run-tests.sh Trevor Woerner
2026-07-06 8:33 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 05/10] tests: add ruff linting " Trevor Woerner
2026-07-06 8:40 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 06/10] tests/docs: add the suite overview README Trevor Woerner
2026-07-06 8:47 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 07/10] tests/docs: add the test-authoring guide Trevor Woerner
2026-07-06 8:52 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 08/10] tests: ignore E402 in the test tree for the sys.path bootstrap Trevor Woerner
2026-07-06 8:55 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 09/10] tests/unit/test_bb_utils: test mkdirhier() and fix its missing errno import Trevor Woerner
2026-07-06 9:06 ` [yocto-patches] " Paul Barker
2026-07-01 7:40 ` [wic][PATCH v3 10/10] tests/docs: add the review rubric Trevor Woerner
2026-07-06 9:08 ` [yocto-patches] " Paul Barker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260701074030.1090807-4-twoerner@gmail.com \
--to=twoerner@gmail.com \
--cc=yocto-patches@lists.yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.