From bc62197787c3f57c6dce972c40a7a853f33c92dd Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 9 Dec 2024 12:07:40 +0100 Subject: [PATCH 1/7] fix --- src/pytest_subtests/plugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pytest_subtests/plugin.py b/src/pytest_subtests/plugin.py index 316e1c0..fa24ee6 100644 --- a/src/pytest_subtests/plugin.py +++ b/src/pytest_subtests/plugin.py @@ -105,8 +105,10 @@ def _addSkip(self: TestCaseFunction, testcase: TestCase, reason: str) -> None: self.addSubTest(testcase.test_case, testcase, exc_info) # type: ignore[attr-defined] else: # For python < 3.11: the non-subtest skips have to be added by `_originaladdSkip` only after all subtest - # failures are processed by `_addSubTest`. - if sys.version_info < (3, 11): + # failures are processed by `_addSubTest`. (`self.instance._outcome` has no attribute `skipped/errors` anymore.) + # For python < 3.11, we also need to check if `self.instance._outcome` is `None` (this happens if the test + # class/method is decorated with `unittest.skip`). + if sys.version_info < (3, 11) and self.instance._outcome is not None: subtest_errors = [ x for x, y in self.instance._outcome.errors From e68514155abb08879dfaf98c64a438ce89e99fbc Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 9 Dec 2024 13:19:33 +0100 Subject: [PATCH 2/7] add test --- tests/test_subtests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 8ec97bf..647eedb 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -336,6 +336,32 @@ def test_foo(self): ["collected 1 item", "* 3 xfailed, 1 passed in *"] ) + # A test for https://github.com/pytest-dev/pytest-subtests/issues/173 + @pytest.mark.parametrize("runner", ["pytest-normal"]) + def test_only_original_skip_is_called( + self, + pytester: pytest.Pytester, + monkeypatch: pytest.MonkeyPatch, + runner: Literal["pytest-normal"], + ) -> None: + monkeypatch.setenv("COLUMNS", "200") + p = pytester.makepyfile( + """ + import unittest + from unittest import TestCase, main + + @unittest.skip("skip this test") + class T(unittest.TestCase): + def test_foo(self): + assert 1 == 2 + + if __name__ == '__main__': + main() + """ + ) + result = pytester.runpytest(p, "-v", "-rsf") + result.stdout.fnmatch_lines(["SKIPPED [1] test_only_original_skip_is_called.py:6: skip this test"]) + @pytest.mark.parametrize("runner", ["unittest", "pytest-normal", "pytest-xdist"]) def test_skip_with_failure( self, From 6e809d74ec5a2d1b5d19c0e4920407395962b16f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:20:18 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_subtests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 647eedb..34096fa 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -360,7 +360,9 @@ def test_foo(self): """ ) result = pytester.runpytest(p, "-v", "-rsf") - result.stdout.fnmatch_lines(["SKIPPED [1] test_only_original_skip_is_called.py:6: skip this test"]) + result.stdout.fnmatch_lines( + ["SKIPPED [1] test_only_original_skip_is_called.py:6: skip this test"] + ) @pytest.mark.parametrize("runner", ["unittest", "pytest-normal", "pytest-xdist"]) def test_skip_with_failure( From 493e30d411ab44cb7295520fe3c75c32ffd722e1 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:13:34 +0100 Subject: [PATCH 4/7] Update tests/test_subtests.py Co-authored-by: Bruno Oliveira --- tests/test_subtests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_subtests.py b/tests/test_subtests.py index 34096fa..299db77 100644 --- a/tests/test_subtests.py +++ b/tests/test_subtests.py @@ -336,7 +336,6 @@ def test_foo(self): ["collected 1 item", "* 3 xfailed, 1 passed in *"] ) - # A test for https://github.com/pytest-dev/pytest-subtests/issues/173 @pytest.mark.parametrize("runner", ["pytest-normal"]) def test_only_original_skip_is_called( self, @@ -344,6 +343,7 @@ def test_only_original_skip_is_called( monkeypatch: pytest.MonkeyPatch, runner: Literal["pytest-normal"], ) -> None: + """Regression test for #173.""" monkeypatch.setenv("COLUMNS", "200") p = pytester.makepyfile( """ From 8965561c8c0f12293872550818ffe703c000fa93 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:14:07 +0100 Subject: [PATCH 5/7] Update src/pytest_subtests/plugin.py Co-authored-by: Bruno Oliveira --- src/pytest_subtests/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_subtests/plugin.py b/src/pytest_subtests/plugin.py index fa24ee6..969285a 100644 --- a/src/pytest_subtests/plugin.py +++ b/src/pytest_subtests/plugin.py @@ -107,7 +107,7 @@ def _addSkip(self: TestCaseFunction, testcase: TestCase, reason: str) -> None: # For python < 3.11: the non-subtest skips have to be added by `_originaladdSkip` only after all subtest # failures are processed by `_addSubTest`. (`self.instance._outcome` has no attribute `skipped/errors` anymore.) # For python < 3.11, we also need to check if `self.instance._outcome` is `None` (this happens if the test - # class/method is decorated with `unittest.skip`). + # class/method is decorated with `unittest.skip`, see #173). if sys.version_info < (3, 11) and self.instance._outcome is not None: subtest_errors = [ x From 271257615c223813d8b76727f722017dc0172c71 Mon Sep 17 00:00:00 2001 From: ydshieh Date: Mon, 9 Dec 2024 14:19:15 +0100 Subject: [PATCH 6/7] update CHANGELOG.rst --- CHANGELOG.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6373e51..40bdc7e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ CHANGELOG ========= +0.14.1 +------ + +*2024-12-09* + +* Fix ``self.instance._outcome`` is ``None`` case in #173 (`#174`_). + +.. _#174: https://github.com/pytest-dev/pytest-subtests/pull/174 + 0.14.0 ------ From 30655225c4b20bd1977af011b7bfb7432023d079 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 9 Dec 2024 21:08:43 -0300 Subject: [PATCH 7/7] Fix CHANGELOG back to unreleased --- CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40bdc7e..02e8fdd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,10 +1,10 @@ CHANGELOG ========= -0.14.1 ------- +UNRELEASED +---------- -*2024-12-09* +*UNRELEASED* * Fix ``self.instance._outcome`` is ``None`` case in #173 (`#174`_).