Skip to content

Commit 1097174

Browse files
committed
tests/run-multitests.py: Don't allow imports from the cwd.
Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 4216bc7 commit 1097174

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/run-multitests.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ def __init__(self, argv, env=None):
162162
def __str__(self):
163163
return self.argv[0].rsplit("/")[-1]
164164

165+
def prepare_script_from_file(self, filename, prepend, append):
166+
# Make tests run in an isolated environment (i.e. `import io` would
167+
# otherwise get the `tests/io` directory).
168+
remove_cwd_from_sys_path = b"import sys\nsys.path.remove('')\n\n"
169+
return remove_cwd_from_sys_path + super().prepare_script_from_file(
170+
filename, prepend, append
171+
)
172+
165173
def run_script(self, script):
166174
output = b""
167175
err = None
@@ -582,7 +590,7 @@ def main():
582590
cmd_args = cmd_parser.parse_args()
583591

584592
# clear search path to make sure tests use only builtin modules and those in extmod
585-
os.environ["MICROPYPATH"] = os.pathsep.join(("", ".frozen", "../extmod"))
593+
os.environ["MICROPYPATH"] = os.pathsep.join((".frozen", "../extmod"))
586594

587595
test_files = prepare_test_file_list(cmd_args.files)
588596
max_instances = max(t[1] for t in test_files)

0 commit comments

Comments
 (0)