Author xtreak
Recipients defreng, ezio.melotti, michael.foord, rbcollins, xtreak
Date 2020-07-17.10:17:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594981078.76.0.876648437229.issue41322@roundup.psfhosted.org>
In-reply-to
Content
https://github.com/python/cpython/blob/8e836bb21ce73f0794fd769db5883c29680dfe47/Lib/unittest/case.py#L548 . _callTestMethod just calls the test method and doesn't check for the method to be a generator function to be iterated through. In Python 3.8 the call to test method was separated out as _callTestMethod. So something like below added in the original method should work. I guess there is an existing issue for this.


import unittest
from unittest import TestCase

class BuggyTestCase(TestCase):

    def _callTestMethod(self, method):
        import inspect

        if inspect.isgeneratorfunction(method):
            list(method())
        else:
            method()

    def test_generator(self):
        self.assertTrue(False)
        yield None

if __name__ == "__main__":
    unittest.main()


python3.8 test_foo.py
F
======================================================================
FAIL: test_generator (__main__.BuggyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_foo.py", line 10, in _callTestMethod
    list(method())
  File "test_foo.py", line 15, in test_generator
    self.assertTrue(False)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
History
Date User Action Args
2020-07-17 10:17:58xtreaksetrecipients: + xtreak, rbcollins, ezio.melotti, michael.foord, defreng
2020-07-17 10:17:58xtreaksetmessageid: <1594981078.76.0.876648437229.issue41322@roundup.psfhosted.org>
2020-07-17 10:17:58xtreaklinkissue41322 messages
2020-07-17 10:17:58xtreakcreate