Skip to content

Commit e323da7

Browse files
committed
tests/run-tests.py: Set name of injected test module to '__main__'.
Running unittest-based tests with --via-mpy is currently broken, because the unittest test needs the module to be named `__main__`, whereas it's actually called `__injected_test`. Fix this by changing the name when the file is opened. Signed-off-by: Damien George <[email protected]>
1 parent 3c1722e commit e323da7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tests/run-tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ def base_path(*p):
5959
os.environ["PYTHONIOENCODING"] = "utf-8"
6060

6161
# Code to allow a target MicroPython to import an .mpy from RAM
62+
# Note: the module is named `__injected_test` but it needs to have `__name__` set to
63+
# `__main__` so that the test sees itself as the main module, eg so unittest works.
6264
injected_import_hook_code = """\
6365
import sys, os, io, vfs
6466
class __File(io.IOBase):
6567
def __init__(self):
68+
sys.modules['__injected_test'].__name__ = '__main__'
6669
self.off = 0
6770
def ioctl(self, request, arg):
6871
return 0

0 commit comments

Comments
 (0)