diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2023-05-11 14:28:35 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-05-18 13:48:21 +1000 |
| commit | 17127bbee52f2c674c5c79b675fabacea7bc2751 (patch) | |
| tree | f776a6511f071eb3a6dff24673d8606bbaf97b45 /tests/run-tests.py | |
| parent | ab3f9ecb595bf114c744e253cdbd6d1e42951d2f (diff) | |
tests/run-tests.py: Ensure correct cwd for mpy tests.
Previously when using --via-mpy, the file was compiled to tests/<tmp>.mpy
and then run using `micropython -m <tmp>` in the current cwd
(usually tests/). This meant that an import in the test would be resolved
relative to tests/.
This is different to regular (non-via-mpy) tests, where we run (for
example) `micropython basics/test.py` which means that an import would be
resolved relative to basics/.
Now --via-mpy matches the .py behavior. This is important because:
a) It makes it so import tests do the right thing.
b) There are directory names in tests/ that match built-in module names.
Furthermore, it always ensures the cwd (for both micropython and cpython)
is the test directory (e.g. basics/) rather than being left unset. This
also makes it clearer inside the test that e.g. file access is relative to
the Python file.
Updated tests with file paths to match.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/run-tests.py')
| -rwxr-xr-x | tests/run-tests.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/run-tests.py b/tests/run-tests.py index 03269a9f1..498db8b40 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -261,29 +261,31 @@ def run_micropython(pyb, args, test_file, is_special=False): # a standard test run on PC # create system command - cmdlist = [MICROPYTHON, "-X", "emit=" + args.emit] + cmdlist = [os.path.abspath(MICROPYTHON), "-X", "emit=" + args.emit] if args.heapsize is not None: cmdlist.extend(["-X", "heapsize=" + args.heapsize]) if sys.platform == "darwin": cmdlist.extend(["-X", "realtime"]) + cwd = os.path.dirname(test_file) + # if running via .mpy, first compile the .py file if args.via_mpy: - mpy_modname = tempfile.mktemp(dir="") - mpy_filename = mpy_modname + ".mpy" + mpy_filename = tempfile.mktemp(dir=cwd, suffix=".mpy") subprocess.check_output( [MPYCROSS] + args.mpy_cross_flags.split() + ["-o", mpy_filename, "-X", "emit=" + args.emit, test_file] ) + mpy_modname = os.path.splitext(os.path.basename(mpy_filename))[0] cmdlist.extend(["-m", mpy_modname]) else: - cmdlist.append(test_file) + cmdlist.append(os.path.abspath(test_file)) # run the actual test try: output_mupy = subprocess.check_output( - cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT + cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT, cwd=cwd ) except subprocess.CalledProcessError as er: had_crash = True @@ -707,7 +709,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): else: # run CPython to work out expected output try: - output_expected = subprocess.check_output(CPYTHON3_CMD + [test_file]) + output_expected = subprocess.check_output( + CPYTHON3_CMD + [os.path.abspath(test_file)], cwd=os.path.dirname(test_file) + ) if args.write_exp: with open(test_file_expected, "wb") as f: f.write(output_expected) |
