def test_pantsd_file_logging(self) -> None:
        with self.pantsd_successful_run_context("debug") as ctx:
            daemon_run = ctx.runner([
                "--backend-packages=pants.backend.python", "list", "3rdparty::"
            ])
            ctx.checker.assert_started()
            assert "[DEBUG] Connecting to pantsd on port" in daemon_run.stderr
            assert "[DEBUG] Connected to pantsd" in daemon_run.stderr

            pants_log = "\n".join(read_pants_log(ctx.workdir))
            assert "[INFO] handling request" in pants_log
    def pantsd_test_context(
        self,
        *,
        log_level: str = "info",
        extra_config: dict[str, Any] | None = None
    ) -> Iterator[tuple[str, dict[str, Any], PantsDaemonMonitor]]:
        with temporary_dir(root_dir=os.getcwd()) as workdir_base:
            pid_dir = os.path.join(workdir_base, ".pids")
            workdir = os.path.join(workdir_base, ".workdir.pants.d")
            print(f"\npantsd log is {workdir}/pantsd/pantsd.log")
            pantsd_config = {
                "GLOBAL": {
                    "pantsd":
                    True,
                    "level":
                    log_level,
                    "pants_subprocessdir":
                    pid_dir,
                    "backend_packages": [
                        # Provide goals used by various tests.
                        "pants.backend.python",
                        "pants.backend.python.lint.flake8",
                    ],
                }
            }

            if extra_config:
                recursively_update(pantsd_config, extra_config)
            print(f">>> config: \n{pantsd_config}\n")

            checker = PantsDaemonMonitor(pid_dir)
            kill_daemon(pid_dir)
            try:
                yield workdir, pantsd_config, checker
                kill_daemon(pid_dir)
                checker.assert_stopped()
            finally:
                banner("BEGIN pants.log")
                for line in read_pants_log(workdir):
                    print(line)
                banner("END pants.log")
Esempio n. 3
0
 def full_pants_log():
     return "\n".join(read_pants_log(ctx.workdir))