@@ -1965,6 +1965,7 @@ def _supports_remote_attaching():
19651965 "Test only runs on Linux, Windows and MacOS" )
19661966@unittest .skipIf (sys .platform == "linux" and not _supports_remote_attaching (),
19671967 "Test only runs on Linux with process_vm_readv support" )
1968+ @test .support .cpython_only
19681969class TestRemoteExec (unittest .TestCase ):
19691970 def tearDown (self ):
19701971 test .support .reap_children ()
@@ -2152,5 +2153,31 @@ def test_remote_exec_invalid_script_path(self):
21522153 with self .assertRaises (OSError ):
21532154 sys .remote_exec (os .getpid (), "invalid_script_path" )
21542155
2156+ def test_remote_exec_in_process_without_debug_fails_envvar (self ):
2157+ """Test remote exec in a process without remote debugging enabled"""
2158+ script = os_helper .TESTFN + '_remote.py'
2159+ self .addCleanup (os_helper .unlink , script )
2160+ with open (script , 'w' ) as f :
2161+ f .write ('print("Remote script executed successfully!")' )
2162+ env = os .environ .copy ()
2163+ env ['PYTHON_DISABLE_REMOTE_DEBUG' ] = '1'
2164+
2165+ _ , out , err = assert_python_failure ('-c' , f'import os, sys; sys.remote_exec(os.getpid(), "{ script } ")' , ** env )
2166+ self .assertIn (b"Remote debugging is not enabled" , err )
2167+ self .assertEqual (out , b"" )
2168+
2169+ def test_remote_exec_in_process_without_debug_fails_xoption (self ):
2170+ """Test remote exec in a process without remote debugging enabled"""
2171+ script = os_helper .TESTFN + '_remote.py'
2172+ self .addCleanup (os_helper .unlink , script )
2173+ with open (script , 'w' ) as f :
2174+ f .write ('print("Remote script executed successfully!")' )
2175+
2176+ _ , out , err = assert_python_failure ('-Xdisable-remote-debug' , '-c' , f'import os, sys; sys.remote_exec(os.getpid(), "{ script } ")' )
2177+ self .assertIn (b"Remote debugging is not enabled" , err )
2178+ self .assertEqual (out , b"" )
2179+
2180+
2181+
21552182if __name__ == "__main__" :
21562183 unittest .main ()
0 commit comments