Package: pytest
Version: 8.2.2-1
Severity: important
Tags: patch
X-Debbugs-Cc: chris.peter...@canonical.com
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu oracular ubuntu-patch




Hi,

Pytest 8.2.2 introduced a regression in flaky test plugins (e.g.
pytest-rerunfailures and python-flaky) that causes AssertionErrors when
re-running tests in test classes which inherit from unittest.TestCase.
I applied the following patch in Ubuntu to fix the issue.

  * 0003-pytest8-testcase-assertion.patch: Fixes unittest regression in
    flaky test plugins (LP: #2068642).

Thanks for considering the patch.


-- System Information:
Debian Release: trixie/sid
  APT prefers oracular
  APT policy: (500, 'oracular'), (100, 'oracular-proposed')
Architecture: amd64 (x86_64)

Kernel: Linux 6.8.0-31-generic (SMP w/16 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru pytest-8.2.2/debian/patches/0003-pytest8-testcase-assertion.patch 
pytest-8.2.2/debian/patches/0003-pytest8-testcase-assertion.patch
--- pytest-8.2.2/debian/patches/0003-pytest8-testcase-assertion.patch   
1969-12-31 16:00:00.000000000 -0800
+++ pytest-8.2.2/debian/patches/0003-pytest8-testcase-assertion.patch   
2024-06-07 15:23:04.000000000 -0700
@@ -0,0 +1,48 @@
+Description: Fix unittest regressions for flaky test plugins
+ A change in the behavior of the unittest teardown function caused a
+ regression in plugins that re-ran tests. Namely python-flaky and
+ pytest-rerunfailures. This patch was cherry-picked from an upstream
+ PR.
+Origin: upstream, https://github.com/pytest-dev/pytest/pull/12436
+Bug: https://github.com/pytest-dev/pytest/issues/12424
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/pytest/+bug/2068642
+Forwarded: not-needed
+Last-Update: 2024-06-07
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/src/_pytest/unittest.py
++++ b/src/_pytest/unittest.py
+@@ -216,7 +216,7 @@
+             self._explicit_tearDown()
+             self._explicit_tearDown = None
+         self._obj = None
+-        self._instance = None
++        del self._instance
+         super().teardown()
+ 
+     def startTest(self, testcase: "unittest.TestCase") -> None:
+--- /dev/null
++++ b/testing/plugins_integration/pytest_rerunfailures_integration.py
+@@ -0,0 +1,11 @@
++import unittest
++
++
++class MyTestCase(unittest.TestCase):
++    first_time = True
++
++    def test_fail_the_first_time(self) -> None:
++        """Regression test for issue #12424."""
++        if self.first_time:
++            type(self).first_time = False
++            self.fail()
+--- a/tox.ini
++++ b/tox.ini
+@@ -143,7 +143,7 @@
+     pytest --cov=. simple_integration.py
+     pytest --ds=django_settings simple_integration.py
+     pytest --html=simple.html simple_integration.py
+-    pytest --reruns 5 simple_integration.py
++    pytest --reruns 5 simple_integration.py 
pytest_rerunfailures_integration.py
+     pytest pytest_anyio_integration.py
+     pytest pytest_asyncio_integration.py
+     pytest pytest_mock_integration.py
diff -Nru pytest-8.2.2/debian/patches/series pytest-8.2.2/debian/patches/series
--- pytest-8.2.2/debian/patches/series  2024-06-05 06:34:35.000000000 -0700
+++ pytest-8.2.2/debian/patches/series  2024-06-07 09:09:35.000000000 -0700
@@ -1,2 +1,3 @@
 0001-Use-local-intersphinx-mappings.patch
 0002-Disable-Sphinx-extensions.patch
+0003-pytest8-testcase-assertion.patch

Reply via email to