You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/skills/pytest-infra.md
+20-15Lines changed: 20 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,43 +139,48 @@ When migrating a legacy `test-*.py` to `pytest-*.py`:
139
139
140
140
## Handling `on_fail=test.ABORT`
141
141
142
-
The legacy framework supported `with test.closure('Name', on_fail=test.ABORT):` — if that closure failed, all subsequent closures were skipped. In pytest, use the**`pytest-dependency`**plugin (already in`requirements.txt`and`plugins.py`).
142
+
The legacy framework supported `with test.closure('Name', on_fail=test.ABORT):` — if that closure failed, all subsequent closures were skipped. In pytest, use a**module-level state dict**with`pytest.skip()`.
143
143
144
-
**Pattern**: mark the prerequisite test with`@pytest.mark.dependency(scope='module')`, and each dependent test with`@pytest.mark.dependency(scope='module', depends=["prerequisite_name"])`. If the prerequisite fails oris skipped, all dependents are automatically skipped.
144
+
>**Why not`pytest-dependency`?** The plugin requires exact test-name matching, but `pytest_generate_tests` (used by `device_each`) appends parametrized suffixes like `[D455-1234567890]`. The plugin cannot match `"test_foo"` against `"test_foo[D455-1234567890]"` — no regex, glob, or prefix support exists. The module-state pattern is zero-dependency and works regardless of parametrization.
145
+
146
+
**Pattern**: the prerequisite test sets a flag in a module-level dict on success. Dependent tests check the flag and`pytest.skip()`if missing.
145
147
146
148
```python
147
-
# Prerequisite test — asserts (hard fail if condition not met), registers as a dependency
**`scope='module'`**: limits dependency resolution to the current test file, so identically-named tests in other files do not interfere.
162
-
163
-
**Parametrized tests**: when both the prerequisite and dependent tests share the same parametrization (e.g., `device_each`), `pytest-dependency` automatically matches per-parameter — `test_set_depth_control[D455-SN]`is only skipped if`test_advanced_mode_support[D455-SN]` specifically failed, notif a different device's run failed.
164
-
165
-
**Chain of ABORTs**: if a file has multiple `on_fail=test.ABORT` closures in sequence, listall prerequisite names in`depends=`:
164
+
**Chain of ABORTs**: if a file has multiple prerequisite tests in sequence, each sets its own flag. Dependents check the deepest prerequisite (which implicitly requires all prior ones to have passed):
166
165
167
166
```python
168
-
@pytest.mark.dependency(scope='module')
167
+
_module_state = {}
168
+
169
169
def test_advanced_mode_support(...): # first ABORT
0 commit comments