(self, script=None)
| 1021 | self.port = self.server_sock.getsockname()[1] |
| 1022 | |
| 1023 | def _create_script(self, script=None): |
| 1024 | # Create a file for subprocess script |
| 1025 | if script is None: |
| 1026 | script = textwrap.dedent( |
| 1027 | f""" |
| 1028 | import pdb |
| 1029 | import sys |
| 1030 | import time |
| 1031 | |
| 1032 | def foo(): |
| 1033 | x = 42 |
| 1034 | return bar() |
| 1035 | |
| 1036 | def bar(): |
| 1037 | return 42 |
| 1038 | |
| 1039 | def connect_to_debugger(): |
| 1040 | # Create a frame to debug |
| 1041 | def dummy_function(): |
| 1042 | x = 42 |
| 1043 | # Call connect to establish connection |
| 1044 | # with the test server |
| 1045 | frame = sys._getframe() # Get the current frame |
| 1046 | pdb._connect( |
| 1047 | host='127.0.0.1', |
| 1048 | port={self.port}, |
| 1049 | frame=frame, |
| 1050 | commands="", |
| 1051 | version=pdb._PdbServer.protocol_version(), |
| 1052 | signal_raising_thread=False, |
| 1053 | colorize=False, |
| 1054 | ) |
| 1055 | return x # This line won't be reached in debugging |
| 1056 | |
| 1057 | return dummy_function() |
| 1058 | |
| 1059 | result = connect_to_debugger() |
| 1060 | foo() |
| 1061 | print(f"Function returned: {{result}}") |
| 1062 | """) |
| 1063 | |
| 1064 | self.script_path = TESTFN + "_connect_test.py" |
| 1065 | with open(self.script_path, 'w') as f: |
| 1066 | f.write(script) |
| 1067 | |
| 1068 | def tearDown(self): |
| 1069 | self.server_sock.close() |
no test coverage detected