From 52aa761e814d4981954ede175fd12705b0042c24 Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Wed, 24 Jan 2024 13:15:15 +0200 Subject: [PATCH] Fix usage of deprecated startdir parameter Use the start_path parameter instead of startdir for Pytest 7 or newer, since Pytest 7 yields the following deprecation warning if startdir is being used: site-packages/pytest_sugar.py:279: PytestRemovedIn8Warning: The (startdir: py.path.local) argument is deprecated, please use (start_path: pathlib.Path) Details of the Pytest deprecation can be found from: https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path Fixes #232 --- pytest_sugar.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pytest_sugar.py b/pytest_sugar.py index 81441f2..b0b266a 100644 --- a/pytest_sugar.py +++ b/pytest_sugar.py @@ -276,8 +276,12 @@ def pytest_sessionstart(self, session: Session) -> None: ), bold=True, ) + if int(pytest.__version__.split(".")[0]) <= 6: + hook_call_kwargs = {"startdir": self.startpath} + else: + hook_call_kwargs = {"start_path": self.startpath} lines = self.config.hook.pytest_report_header( - config=self.config, startdir=self.startpath + config=self.config, **hook_call_kwargs ) lines.reverse() for line in flatten(lines):