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["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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy