diff --git a/tests/base.py b/tests/base.py index 4edfd86db..5b0cfe018 100644 --- a/tests/base.py +++ b/tests/base.py @@ -61,30 +61,38 @@ def __setup(self): # self._port = get_random_port() self._commands = "" - self._command = [ - # fmt: off - self._gdb_path, "-q", "-nx", - "-ex", f"source {GEF_PATH}", - "-ex", "gef config gef.debug True", - "-ex", "gef config gef.propagate_debug_exception True", - "-ex", "gef config gef.disable_color True", - "-ex", f"source {RPYC_GEF_PATH}", - "-ex", f"pi start_rpyc_service({self._port})", - # fmt: on - ] if COVERAGE_DIR: self._coverage_file = pathlib.Path(COVERAGE_DIR) / os.getenv( "PYTEST_XDIST_WORKER", "gw0" ) - self._command.extend(("-ex", - f"""pi import coverage; cov = coverage.Coverage(data_file="{self._coverage_file}", auto_data=True, branch=True); cov.start()""")) + self._commands += f""" +pi import coverage +pi cov = coverage.Coverage(data_file="{self._coverage_file}", auto_data=True, branch=True) +pi cov.start() +""" - self._command.extend( - ("--", - str(self._target.absolute()) # type: ignore pylint: disable=E1101 - ) - ) + self._commands += f""" +source {GEF_PATH} +gef config gef.debug True +gef config gef.propagate_debug_exception True +gef config gef.disable_color True +source {RPYC_GEF_PATH} +pi start_rpyc_service({self._port}) +""" + + self._initfile = tempfile.NamedTemporaryFile(mode="w", delete=False) + self._initfile.write(self._commands) + self._initfile.flush() + self._command = [ + "gdb", + "-q", + "-nx", + "-ex", + f"source {self._initfile.name}", + "--", + str(self._target.absolute()), # type: ignore pylint: disable=E1101 + ] self._process = subprocess.Popen(self._command) assert self._process.pid > 0