tests/cmdline: Add tests for using -m combined with sys.atexit.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-09-22 11:41:36 +10:00
parent 8c389db6ea
commit bf08f601fa
4 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
# cmdline: -m cmdline.cmd_module_atexit
#
# Test running as a module and using sys.atexit.
import sys
if not hasattr(sys, "atexit"):
print("SKIP")
raise SystemExit
# Verify we ran as a module.
print(sys.argv)
sys.atexit(lambda: print("done"))
print("start")

View File

@@ -0,0 +1,3 @@
['cmdline.cmd_module_atexit', 'cmdline/cmd_module_atexit.py']
start
done

View File

@@ -0,0 +1,19 @@
# cmdline: -m cmdline.cmd_module_atexit_exc
#
# Test running as a module and using sys.atexit, with script completion via sys.exit.
import sys
if not hasattr(sys, "atexit"):
print("SKIP")
raise SystemExit
# Verify we ran as a module.
print(sys.argv)
sys.atexit(lambda: print("done"))
print("start")
# This will raise SystemExit to finish the script, and atexit should still be run.
sys.exit(0)

View File

@@ -0,0 +1,3 @@
['cmdline.cmd_module_atexit_exc', 'cmdline/cmd_module_atexit_exc.py']
start
done