Skip to content

Commit 6fd7422

Browse files
agattidpgeorge
authored andcommitted
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>
1 parent 0d43595 commit 6fd7422

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/run-tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def open(self, path, mode):
9595
return __File()
9696
vfs.mount(__FS(), '/__vfstest')
9797
os.chdir('/__vfstest')
98+
{import_prologue}
9899
__import__('__injected_test')
99100
"""
100101

@@ -1130,6 +1131,8 @@ def __call__(self, parser, args, value, option):
11301131

11311132

11321133
def main():
1134+
global injected_import_hook_code
1135+
11331136
cmd_parser = argparse.ArgumentParser(
11341137
formatter_class=argparse.RawDescriptionHelpFormatter,
11351138
description="""Run and manage tests for MicroPython.
@@ -1239,8 +1242,20 @@ def main():
12391242
action="store_true",
12401243
help="re-run only the failed tests",
12411244
)
1245+
cmd_parser.add_argument(
1246+
"--begin",
1247+
metavar="PROLOGUE",
1248+
default=None,
1249+
help="prologue python file to execute before module import",
1250+
)
12421251
args = cmd_parser.parse_args()
12431252

1253+
prologue = ""
1254+
if args.begin:
1255+
with open(args.begin, "rt") as source:
1256+
prologue = source.read()
1257+
injected_import_hook_code = injected_import_hook_code.replace("{import_prologue}", prologue)
1258+
12441259
if args.print_failures:
12451260
for out in glob(os.path.join(args.result_dir, "*.out")):
12461261
testbase = out[:-4]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy