Skip to content

Commit

Permalink
tests/run-multitests.py: Don't allow imports from the cwd.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jimmo committed Jun 8, 2023
1 parent 4216bc7 commit 1097174
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/run-multitests.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def __init__(self, argv, env=None):
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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1097174

Please sign in to comment.