From 861b6a06575e764d751eee4aa7929b21cee7e32e Mon Sep 17 00:00:00 2001 From: Konrad Weihmann <46938494+priv-kweihmann@users.noreply.github.com> Date: Mon, 10 Nov 2025 23:57:15 +0100 Subject: [PATCH] Adapt to API deprecation in pytest 9.x (#39) Signed-off-by: Konrad Weihmann Co-authored-by: Russell Keith-Magee --- .github/dependabot.yml | 19 +++++++ .github/workflows/ci.yml | 57 +++++-------------- .github/workflows/pre-commit-update.yml | 18 ++++++ .pre-commit-config.yaml | 32 +++-------- changes/39.feature.1.rst | 1 + changes/39.feature.2.rst | 1 + changes/39.feature.3.rst | 1 + changes/39.removal.1.rst | 1 + changes/39.removal.2.rst | 1 + pyproject.toml | 74 ++++++++++++++++++++----- pytest_tldr.py | 31 +++-------- tests/test_plugins.py | 2 +- tests/test_unittest.py | 10 ---- tox.ini | 49 +++------------- 14 files changed, 144 insertions(+), 153 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/pre-commit-update.yml create mode 100644 changes/39.feature.1.rst create mode 100644 changes/39.feature.2.rst create mode 100644 changes/39.feature.3.rst create mode 100644 changes/39.removal.1.rst create mode 100644 changes/39.removal.2.rst Index: pytest-tldr-0.2.5/pytest_tldr.py =================================================================== --- pytest-tldr-0.2.5.orig/pytest_tldr.py +++ pytest-tldr-0.2.5/pytest_tldr.py @@ -6,17 +6,6 @@ import pluggy import py import pytest -try: - from pytest import ExitCode -except ImportError: - # PyTest <5 compatibibility - from _pytest.main import EXIT_OK, EXIT_TESTSFAILED - - class ExitCode: - OK = EXIT_OK - TESTS_FAILED = EXIT_TESTSFAILED - - __version__ = "0.2.5" @@ -35,12 +24,11 @@ def pytest_configure(config): def _plugin_nameversions(plugininfo): values = [] - for plugin, dist in plugininfo: + for _, dist in plugininfo: # gets us name and version! - name = "{dist.project_name}-{dist.version}".format(dist=dist) + name = f"{dist.project_name}-{dist.version}" # questionable convenience, but it keeps things short - if name.startswith("pytest-"): - name = name[7:] + name = name.removeprefix("pytest-") # we decided to print python package names # they can have more than one plugin if name not in values: @@ -71,7 +59,7 @@ class TLDRReporter: # Plugin compatibility methods. # # TLDR overwrites TerminalReporter, but some plugins depend - # on the outout capabilities of TerminalReporter. Preserve them, + # on the output capabilities of TerminalReporter. Preserve them, # to the extent possible. ###################################################################### @@ -158,7 +146,7 @@ class TLDRReporter: self.print(f"pluggy=={pluggy.__version__}") headers = self.config.hook.pytest_report_header( - config=self.config, startdir=py.path.local() + config=self.config, start_path=py.path.local() ) for header in headers: if isinstance(header, str): @@ -330,14 +318,9 @@ class TLDRReporter: self.print() self.print("-" * 78) - self.print( - "Ran {n_tests} tests in {duration:.2f}s".format( - n_tests=self._n_tests, - duration=duration, - ) - ) + self.print(f"Ran {self._n_tests} tests in {duration:.2f}s") - if exitstatus in {ExitCode.OK, ExitCode.TESTS_FAILED}: + if exitstatus in {pytest.ExitCode.OK, pytest.ExitCode.TESTS_FAILED}: self.config.hook.pytest_terminal_summary( config=self.config, terminalreporter=self, Index: pytest-tldr-0.2.5/tests/test_plugins.py =================================================================== --- pytest-tldr-0.2.5.orig/tests/test_plugins.py +++ pytest-tldr-0.2.5/tests/test_plugins.py @@ -10,7 +10,7 @@ def test_coverage(testdir): result.stdout.fnmatch_lines( [ "test_coverage.py::test_coverage ... ok", - "*_____ coverage: platform *_____", + "* coverage: platform *", "Name Stmts Miss Cover", "--------------------------------------", "test_coverage.py 2 0 100%", Index: pytest-tldr-0.2.5/tests/test_unittest.py =================================================================== --- pytest-tldr-0.2.5.orig/tests/test_unittest.py +++ pytest-tldr-0.2.5/tests/test_unittest.py @@ -1,6 +1,3 @@ -import sys - - def test_pass(testdir): testdir.makepyfile( """ @@ -127,10 +124,3 @@ def test_upass(testdir): "*::TestCase::test_unexpected_success ... unexpected success", ] ) - - # pytest under Python2 reports an unexpected pass as a success, - # but a failure under Python3. - if sys.version_info.major == 2: - assert result.ret == 0 - else: - assert result.ret == 1