micropython/tests/cmdline/cmd_module_atexit_exc.py
Damien George bf08f601fa tests/cmdline: Add tests for using -m combined with sys.atexit.
Signed-off-by: Damien George <damien@micropython.org>
2025-09-23 14:13:37 +10:00

20 lines
408 B
Python

# 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)