From: Trevor Woerner <twoerner@gmail.com>
To: yocto-patches@lists.yoctoproject.org
Subject: [wic][PATCH v2 8/9] tests: ignore E402 in the test tree for the sys.path bootstrap
Date: Tue, 30 Jun 2026 12:06:11 -0400 [thread overview]
Message-ID: <20260630160612.1005451-9-twoerner@gmail.com> (raw)
In-Reply-To: <20260630160612.1005451-1-twoerner@gmail.com>
The unit tests that follow run against a plain checkout that has not
been installed. To do that, each test module prepends the in-tree src/
directory to sys.path and only then imports wic:
_SRC = Path(__file__).resolve().parent.parent.parent / "src"
if str(_SRC) not in sys.path:
sys.path.insert(0, str(_SRC))
from wic.bb.utils import mkdirhier
That bootstrap necessarily runs before the wic imports, which trips
ruff's E402 (module-level import not at top of file). The ordering is
required, not accidental: the import would fail without the sys.path
adjustment ahead of it.
Rather than scatter per-line noqa comments through every test module,
this commit relaxes E402 for the test tree once, via a
[tool.ruff.lint.per-file-ignores] entry scoped to tests/**. It is the
only rule relaxed for tests/; the suite is otherwise held to a clean
bar by --lint-tests.
tests/docs/linting.md gains a section describing this single exception
and why it exists.
AI-Generated: codex/claude-opus 4.7 (xhigh)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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.
---
pyproject.toml | 8 ++++++++
tests/docs/linting.md | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/pyproject.toml b/pyproject.toml
index 656adcd4930a..fb42fe6dd135 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -58,3 +58,11 @@ tmp_path_retention_count = 1
# not yet ruff-clean and is left out until its findings are fixed (see
# tests/docs/linting.md). --lint-src can still be run to preview the
# source findings, but it is reported, not enforced.
+
+[tool.ruff.lint.per-file-ignores]
+# Test modules prepend the in-tree src/ directory to sys.path before
+# importing wic, so the suite runs against a checkout that has not been
+# installed. That bootstrap necessarily runs before the wic imports,
+# which trips E402 (module-level import not at top of file). The
+# ordering is deliberate; ignore E402 for the test tree only.
+"tests/**" = ["E402"]
diff --git a/tests/docs/linting.md b/tests/docs/linting.md
index 71b4de21c100..1c1bfcc06f82 100644
--- a/tests/docs/linting.md
+++ b/tests/docs/linting.md
@@ -4,6 +4,7 @@
- [Running the linter](#running-the-linter)
- [tests/ must be clean](#tests-must-be-clean)
+- [The one intentional exception in tests/](#the-one-intentional-exception-in-tests)
- [src/ is not linted yet](#src-is-not-linted-yet)
The test suite is linted with [ruff](https://docs.astral.sh/ruff/). It
@@ -28,6 +29,25 @@ Our own test code is held to a clean bar: `tests/run-tests.sh
--lint-tests` reports nothing. If you add a test that trips a rule, fix
the test before the change lands.
+## The one intentional exception in tests/
+
+Test modules prepend the in-tree `src/` directory to `sys.path` before
+importing `wic`, so the suite runs against a plain checkout that has not
+been installed:
+
+```python
+_SRC = Path(__file__).resolve().parent.parent.parent / "src"
+if str(_SRC) not in sys.path:
+ sys.path.insert(0, str(_SRC))
+
+from wic.bb.utils import mkdirhier
+```
+
+That bootstrap necessarily runs before the `wic` imports, which trips
+`E402` (module-level import not at top of file). The ordering is
+required, so `E402` is ignored for the test tree via `per-file-ignores`
+in `pyproject.toml`. This is the only rule relaxed for `tests/`.
+
## src/ is not linted yet
`--lint-src` runs ruff over the wic source, but the source is **not**
--
2.50.0.173.g8b6f19ccfc3a
next prev parent reply other threads:[~2026-06-30 16:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 16:06 [wic][PATCH v2 0/9] tests: standalone test-suite framework plus the first unit test Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 1/9] tests: add the standalone test-suite skeleton Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 2/9] tests: add a session banner via conftest.py Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 3/9] tests: add the run-tests.sh wrapper Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 4/9] tests: add optional coverage reporting to run-tests.sh Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 5/9] tests: add ruff linting " Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 6/9] tests/docs: add the suite overview README Trevor Woerner
2026-06-30 16:06 ` [wic][PATCH v2 7/9] tests/docs: add the test-authoring guide Trevor Woerner
2026-06-30 16:06 ` Trevor Woerner [this message]
2026-06-30 16:06 ` [wic][PATCH v2 9/9] tests/unit/test_bb_utils: test mkdirhier() and fix its missing errno import Trevor Woerner
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=20260630160612.1005451-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox