tests/run-tests.py: Ensure correct cwd for mpy tests. #11468
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is necessary for #11456 which currently fails the --via-mpy tests due
import micropython
now attempting to import tests/micropython, but I think it's overall a good fix to improve consistency anyway.Previously when using --via-mpy, the file was compiled to tests/.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.