Repository: pytest-dev/pytest
File: src/_pytest/config/__init__.py (Python)

Code before:
        self.args_source = Config.ArgsSource.ARGS
        self.args: list[str] = []

    @property
    def rootpath(self) -> pathlib.Path:
        """The path to the :ref:`rootdir <rootdir>`.

        :type: pathlib.Path

        .. versionadded:: 6.1
        """
        return self._rootpath

    @property
    def inipath(self) -> pathlib.Path | None:
        """The path to the :ref:`configfile <configfiles>`.

        .. versionadded:: 6.1
        """
        return self._inipath

    def add_cleanup(self, func: _T_callback) -> _T_callback:
        """Add a function to be called when the config object gets out of
        use (usually coinciding with pytest_unconfigure).

        Returns the passed function.
        """
        self._cleanup_stack.callback(func)
        return func

    def _do_configure(self) -> None:
        assert not self._configured
        self._configured = True
        with warnings.catch_warnings():
            warnings.simplefilter("default")
            self.hook.pytest_configure.call_historic(kwargs=dict(config=self))

    def _ensure_unconfigure(self) -> None:
        try:
            if self._configured:
                self._configured = False
                try:
                    self.hook.pytest_unconfigure(config=self)
                finally:
                    self.hook.pytest_configure._call_history = []
        finally:
            try:
                self._cleanup_stack.close()
            finally:
                self._cleanup_stack = contextlib.ExitStack()


Review comment (suggestion):
```suggestion
        Returns the passed function, so you can use @config.add_cleanup as a decorator
```

Code after:
    def rootpath(self) -> pathlib.Path:
        """The path to the :ref:`rootdir <rootdir>`.

        :type: pathlib.Path

        .. versionadded:: 6.1
        """
        return self._rootpath

    @property
    def inipath(self) -> pathlib.Path | None:
        """The path to the :ref:`configfile <configfiles>`.

        .. versionadded:: 6.1
        """
        return self._inipath

    def add_cleanup(self, func: Callable[[], None]) -> None:
        """Add a function to be called when the config object gets out of
        use (usually coinciding with pytest_unconfigure).
        """
        self._cleanup_stack.callback(func)

    def _do_configure(self) -> None:
        assert not self._configured
        self._configured = True
        with warnings.catch_warnings():
            warnings.simplefilter("default")
            self.hook.pytest_configure.call_historic(kwargs=dict(config=self))

    def _ensure_unconfigure(self) -> None:
        try:
            if self._configured:
                self._configured = False
                try:
                    self.hook.pytest_unconfigure(config=self)
                finally:
                    self.hook.pytest_configure._call_history = []
        finally:
            try:
                self._cleanup_stack.close()
            finally:
                self._cleanup_stack = contextlib.ExitStack()

    def get_terminal_writer(self) -> TerminalWriter:
        terminalreporter: TerminalReporter | None = self.pluginmanager.get_plugin(
            "terminalreporter"
        )
        assert terminalreporter is not None
        return terminalreporter._tw