8000 tests/run-tests.py: Set name of injected test module to '__main__'. · micropython/micropython@cdb3f82 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdb3f82

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 <damien@micropython.org>
1 parent d10cda6 commit cdb3f82

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["PYT 7797 HONIOENCODING"] = "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)
0