[lang-ref] ( get_executed_command_path ) ( python )

def test_get_executed_command_path():
    # sys.argv[0] => ./a.py
    ''' examples/get_executed_command_path.py
    import sys

    def print_argv0():
        print(sys.argv[0])

    if __name__ == '__main__':
        print_argv0()
    '''

    ''' examples/get_executed_command_path_call.py
    import get_executed_command_path

    get_executed_command_path.print_argv0()
    '''

    r = subprocess.run([sys.executable, 'examples/get_executed_command_path.py'], capture_output=True, text=True, check=True)
    assert r.stdout.rstrip() == 'examples/get_executed_command_path.py'

    r = subprocess.run([sys.executable, 'examples/get_executed_command_path_call.py'], capture_output=True, text=True, check=True)
    assert r.stdout.rstrip() == 'examples/get_executed_command_path_call.py'