diff options
author | Alessandro Gatti <a.gatti@frob.it> | 2025-06-10 22:54:38 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-07-01 15:43:17 +1000 |
commit | 6fd7422a8e5b6c8952f7b67713f0551992d247cc (patch) | |
tree | 7a6daca4881b0ddfa9ff0b5a2bccd41aa2d596e6 /tests | |
parent | 0d435959e0acf4059cff843e45936c21c6e7eb84 (diff) |
tests/run-tests.py: Allow injected code customisation.
This commit introduces a mechanism to customise the code that is
injected to the board when performing a test file upload and execution.
A new argument, --begin", is added so regular Python code can be
inserted in the injected fragment between the module file creation and
the effective file import. This is needed for running larger tests
(usually ones that have been pre-compiled with
"--via-mpy --emit native") on ESP8266, as that board does not have
enough memory to fit certain blocks of code unless additional
configuration is performed.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/run-tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/run-tests.py b/tests/run-tests.py index 628fde9d3..e45122b10 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -95,6 +95,7 @@ class __FS: return __File() vfs.mount(__FS(), '/__vfstest') os.chdir('/__vfstest') +{import_prologue} __import__('__injected_test') """ @@ -1130,6 +1131,8 @@ class append_filter(argparse.Action): def main(): + global injected_import_hook_code + cmd_parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="""Run and manage tests for MicroPython. @@ -1239,8 +1242,20 @@ the last matching regex is used: action="store_true", help="re-run only the failed tests", ) + cmd_parser.add_argument( + "--begin", + metavar="PROLOGUE", + default=None, + help="prologue python file to execute before module import", + ) args = cmd_parser.parse_args() + prologue = "" + if args.begin: + with open(args.begin, "rt") as source: + prologue = source.read() + injected_import_hook_code = injected_import_hook_code.replace("{import_prologue}", prologue) + if args.print_failures: for out in glob(os.path.join(args.result_dir, "*.out")): testbase = out[:-4] |