summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-12-20 17:03:18 +0100
committerAlessandro Gatti <a.gatti@frob.it>2025-12-26 11:51:56 +0100
commit7173ddee5f979a3c54be7905d6c00aac29a90fda (patch)
tree52f6d9cbdae96f01e2e16a294ae6906cf7fa8dd4 /tests
parent14152e7f49fffdfaa404bf33e00ad247c70e1a4a (diff)
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>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/run-natmodtests.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py
index 50e8d1272..e35e580dc 100755
--- a/tests/run-natmodtests.py
+++ b/tests/run-natmodtests.py
@@ -133,13 +133,6 @@ def detect_architecture(target):
def run_tests(target_truth, target, args, resolved_arch):
- global injected_import_hook_code
-
- prelude = ""
- if args.begin:
- prelude = args.begin.read()
- injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prelude)
-
test_results = []
for test_file in args.files:
# Find supported test
@@ -223,6 +216,8 @@ def run_tests(target_truth, target, args, resolved_arch):
def main():
+ global injected_import_hook_code
+
cmd_parser = argparse.ArgumentParser(
description="Run dynamic-native-module tests under MicroPython",
epilog=run_tests_module.test_instance_epilog,
@@ -240,7 +235,7 @@ def main():
cmd_parser.add_argument(
"-b",
"--begin",
- type=argparse.FileType("rt"),
+ metavar="PROLOGUE",
default=None,
help="prologue python file to execute before module import",
)
@@ -253,6 +248,12 @@ def main():
cmd_parser.add_argument("files", nargs="*", help="input test files")
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_prelude}", prologue)
+
target_truth = TargetSubprocess([CPYTHON3])
target = run_tests_module.get_test_instance(