tests/run-tests.py: Set __main__ module to __injected_test.

When using unittest (for example) with injected mpy files, not only does
the name of the main test module need to be `__main__`, but also the
`__main__` module should correspond to this injected module.  Otherwise the
unittest test won't be detected.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2024-12-20 22:34:42 +11:00
parent 5d12df51fc
commit 91e30df5f2

View File

@@ -65,7 +65,9 @@ injected_import_hook_code = """\
import sys, os, io, vfs
class __File(io.IOBase):
def __init__(self):
sys.modules['__injected_test'].__name__ = '__main__'
module = sys.modules['__injected_test']
module.__name__ = '__main__'
sys.modules['__main__'] = module
self.off = 0
def ioctl(self, request, arg):
if request == 4: # MP_STREAM_CLOSE