[Concept,3/9] test: py: Add --persist flag to keep test artefacts
Commit Message
From: Simon Glass <simon.glass@canonical.com>
When iterating on C test code, the Python fixtures that create disk
images run each time, even though the images have not changed. This
slows down the development cycle unnecessarily.
Add a -P/--persist option to prevent cleanup of test-generated files
like disk images. This allows re-running C tests directly, without
re-running the Python fixture each time.
Update the ext4l test to respect the persist flag.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
doc/develop/py_testing.rst | 7 +++++++
test/py/conftest.py | 3 +++
test/py/tests/test_fs/test_ext4l.py | 4 ++--
3 files changed, 12 insertions(+), 2 deletions(-)
@@ -246,6 +246,13 @@ Command-line options
sets the directory used to store persistent test data. This is test data that
may be re-used across test runs, such as file-system images.
+-P, --persist
+ prevents cleanup of test-generated files like disk images after the test run
+ completes. This is useful when iterating on C test code, allowing you to
+ re-run the C tests without re-running the Python fixture that creates the
+ test images. Note that this must be individually supported by each test, e.g.
+ with a check against u_boot_config.persist before removing images.
+
--timing
shows a histogram of test duration, at the end of the run. The columns are:
@@ -100,6 +100,8 @@ def pytest_addoption(parser):
help="Assume that U-Boot is ready and don't wait for a prompt")
parser.addoption('--timing', default=False, action='store_true',
help='Show info on test timing')
+ parser.addoption('-P', '--persist', default=False, action='store_true',
+ help='Persist test artifacts (do not clean up after tests)')
def run_build(config, source_dir, build_dir, board_type, log):
@@ -346,6 +348,7 @@ def pytest_configure(config):
ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb'
ubconfig.connection_ok = True
ubconfig.timing = config.getoption('timing')
+ ubconfig.persist = config.getoption('persist')
ubconfig.role = config.getoption('role')
ubconfig.allow_exceptions = config.getoption('allow_exceptions')
@@ -65,8 +65,8 @@ class TestExt4l:
yield image_path
- # Cleanup
- if os.path.exists(image_path):
+ # Cleanup (skip if --persist flag is set)
+ if not u_boot_config.persist and os.path.exists(image_path):
os.remove(image_path)
def test_probe(self, ubman, ext4_image):