Skip to content

Commit 7173dde

Browse files
committed
tests/run-natmodtests.py: Explicitly open prelude file.
This change lets the natmod test runner report status information on session end if a prelude script file is chosen. The script serialises its input data as part of the end of session reporting data, but since the prelude file is not a serialisable object serialisation would fail (it's a file handle as far as the argument container structure is aware). Now the file is explicitly open by the script rather than relying on argparse's file handle argument class wrapper. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 14152e7 commit 7173dde

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

tests/run-natmodtests.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ def detect_architecture(target):
133133

134134

135135
def run_tests(target_truth, target, args, resolved_arch):
136-
global injected_import_hook_code
137-
138-
prelude = ""
139-
if args.begin:
140-
prelude = args.begin.read()
141-
injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prelude)
142-
143136
test_results = []
144137
for test_file in args.files:
145138
# Find supported test
@@ -223,6 +216,8 @@ def run_tests(target_truth, target, args, resolved_arch):
223216

224217

225218
def main():
219+
global injected_import_hook_code
220+
226221
cmd_parser = argparse.ArgumentParser(
227222
description="Run dynamic-native-module tests under MicroPython",
228223
epilog=run_tests_module.test_instance_epilog,
@@ -240,7 +235,7 @@ def main():
240235
cmd_parser.add_argument(
241236
"-b",
242237
"--begin",
243-
type=argparse.FileType("rt"),
238+
metavar="PROLOGUE",
244239
default=None,
245240
help="prologue python file to execute before module import",
246241
)
@@ -253,6 +248,12 @@ def main():
253248
cmd_parser.add_argument("files", nargs="*", help="input test files")
254249
args = cmd_parser.parse_args()
255250

251+
prologue = ""
252+
if args.begin:
253+
with open(args.begin, "rt") as source:
254+
prologue = source.read()
255+
injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prologue)
256+
256257
target_truth = TargetSubprocess([CPYTHON3])
257258

258259
target = run_tests_module.get_test_instance(

0 commit comments

Comments
 (0)