Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix self.instance._outcome is None case in #173 #174

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/pytest_subtests/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
ydshieh marked this conversation as resolved.
Show resolved Hide resolved
if sys.version_info < (3, 11) and self.instance._outcome is not None:
subtest_errors = [
x
for x, y in self.instance._outcome.errors
Expand Down
26 changes: 26 additions & 0 deletions tests/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only with pytest case.

@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")
ydshieh marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
Loading