From 3b2b8dd53826ef3b7ef755013e1ecdccd368cb8c Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Mon, 26 May 2025 19:28:40 +1000 Subject: shared/runtime/pyexec: Set __file__ for file input when enabled. When `MICROPY_MODULE___FILE__` is enabled and parsing file input, set the global `__file__` variable to the source filename. This matches the behavior of the unix port and provides the current filename to the executing script. Signed-off-by: Andrew Leech --- tests/cmdline/cmd_file_variable.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/cmdline/cmd_file_variable.py (limited to 'tests/cmdline/cmd_file_variable.py') diff --git a/tests/cmdline/cmd_file_variable.py b/tests/cmdline/cmd_file_variable.py new file mode 100644 index 000000000..6cac6744d --- /dev/null +++ b/tests/cmdline/cmd_file_variable.py @@ -0,0 +1,5 @@ +# Test that __file__ is set correctly for script execution +try: + print("__file__ =", __file__) +except NameError: + print("__file__ not defined") -- cgit v1.2.3