summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-06-02 15:23:23 +1000
committerJim Mussared <jim.mussared@gmail.com>2023-06-08 17:54:24 +1000
commit109717457edbf49421af3848ea26e26fff567289 (patch)
tree53d5229574bc03192db5f80f183c0d3bd6944031
parent4216bc7d1351feb8199e4ebbff1a9598aa1c5b02 (diff)
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 <jim.mussared@gmail.com>
-rwxr-xr-xtests/run-multitests.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/tests/run-multitests.py b/tests/run-multitests.py
index 81db31ea9..5ae8b8ea4 100755
--- a/tests/run-multitests.py
+++ b/tests/run-multitests.py
@@ -162,6 +162,14 @@ class PyInstanceSubProcess(PyInstance):
def __str__(self):
return self.argv[0].rsplit("/")[-1]
+ def prepare_script_from_file(self, filename, prepend, append):
+ # Make tests run in an isolated environment (i.e. `import io` would
+ # otherwise get the `tests/io` directory).
+ remove_cwd_from_sys_path = b"import sys\nsys.path.remove('')\n\n"
+ return remove_cwd_from_sys_path + super().prepare_script_from_file(
+ filename, prepend, append
+ )
+
def run_script(self, script):
output = b""
err = None
@@ -582,7 +590,7 @@ def main():
cmd_args = cmd_parser.parse_args()
# clear search path to make sure tests use only builtin modules and those in extmod
- os.environ["MICROPYPATH"] = os.pathsep.join(("", ".frozen", "../extmod"))
+ os.environ["MICROPYPATH"] = os.pathsep.join((".frozen", "../extmod"))
test_files = prepare_test_file_list(cmd_args.files)
max_instances = max(t[1] for t in test_files)