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

pytest-subtest 0.14.0 fails with Python 3.9 and 3.10 #173

Closed
xqt opened this issue Dec 7, 2024 · 7 comments · Fixed by #174
Closed

pytest-subtest 0.14.0 fails with Python 3.9 and 3.10 #173

xqt opened this issue Dec 7, 2024 · 7 comments · Fixed by #174

Comments

@xqt
Copy link

xqt commented Dec 7, 2024

The new pytest-subtest release 0.14.0 fails with Python 3.9 and 3.10. Here is a traceback we got for tests:

15:10:46     def _addSkip(self: TestCaseFunction, testcase: TestCase, reason: str) -> None:
15:10:46         from unittest.case import _SubTest  # type: ignore[attr-defined]
15:10:46     
15:10:46         if isinstance(testcase, _SubTest):
15:10:46             self._originaladdSkip(testcase, reason)  # type: ignore[attr-defined]
15:10:46             if self._excinfo is not None:
15:10:46                 exc_info = self._excinfo[-1]
15:10:46                 self.addSubTest(testcase.test_case, testcase, exc_info)  # type: ignore[attr-defined]
15:10:46         else:
15:10:46             # For python < 3.11: the non-subtest skips have to be added by `_originaladdSkip` only after all subtest
15:10:46             # failures are processed by `_addSubTest`.
15:10:46             if sys.version_info < (3, 11):
15:10:46                 subtest_errors = [
15:10:46                     x
15:10:46 >                   for x, y in self.instance._outcome.errors
15:10:46                     if isinstance(x, _SubTest) and y is not None
15:10:46                 ]
15:10:46 E               AttributeError: 'NoneType' object has no attribute 'errors'

See for example: https://integration.wikimedia.org/ci/job/pywikibot-core-tox-fasttest-py39/1805/console

@nicoddemus
Copy link
Member

Thanks for the report @xqt!

I will take a look soon, meanwhile cc'ing @ydshieh in case he wants to investigate.

wmfgerrit pushed a commit to wikimedia/pywikibot that referenced this issue Dec 7, 2024
see also:
pytest-dev/pytest-subtests#173

Bug: T381719
Change-Id: I2c7a0e5cc7aea7617070dbce32bc46b072092270
@ydshieh
Copy link
Contributor

ydshieh commented Dec 9, 2024

Hi @xqt Thank you for reporting.

Locally, when I check, I can see self.instance._outcome is unittest.case._Outcome object and its definition (python 3.9 in my environment) is

class _Outcome(object):
    def __init__(self, result=None):
        self.expecting_failure = False
        self.result = result
        self.result_supports_subtests = hasattr(result, "addSubTest")
        self.success = True
        self.skipped = []
        self.expectedFailure = None
        self.errors = []

which have errors.

My python 3.9 is 3.9.20. Also my env with python 3.10.13 also works. Could you provide your full python version.
From the link you provided, I saw it is 3.9.18, but when I checked with a new local env. with python 3.9.18, it still works.

@ydshieh
Copy link
Contributor

ydshieh commented Dec 9, 2024

Ah I see here self.instance._outcome is None! Let me check

@ydshieh
Copy link
Contributor

ydshieh commented Dec 9, 2024

I can reproduce now:

@unittest.skip("bonbon")
class T(unittest.TestCase):
    def test_foo(self):
        assert 1 == 2

It's related to the block

envs\py39\Lib\unittest\case.py

    def run(self, result=None):
        ....
        try:
            breakpoint()
            testMethod = getattr(self, self._testMethodName)
            if (getattr(self.__class__, "__unittest_skip__", False) or
                getattr(testMethod, "__unittest_skip__", False)):
                # If the class or method was skipped.
                skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
                            or getattr(testMethod, '__unittest_skip_why__', ''))
                self._addSkip(result, self, skip_why)
                return result

I will open a PR to fix it.

@ydshieh
Copy link
Contributor

ydshieh commented Dec 9, 2024

A fix is opened #174 🙏 @xqt it would be great if you can also check against that PR 🙏

@loadams
Copy link

loadams commented Dec 9, 2024

I hit this as well, and I was able to confirm the branch in the PR fixes the issue for me.

@nicoddemus
Copy link
Member

0.14.1 released, thanks everyone for reporting and @ydshieh for implementing the fix!

loadams added a commit to microsoft/DeepSpeed that referenced this issue Dec 10, 2024
The issue we encountered was covered here:
pytest-dev/pytest-subtests#173

And is resolved with the latest changes from this PR:
pytest-dev/pytest-subtests#174, and is
published in the latest version 0.14.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants