Skip to content

bpo-41620: Return the result when the test is being skipped#21944

Closed
Tabrizian wants to merge 1 commit intopython:mainfrom
Tabrizian:patch-1
Closed

bpo-41620: Return the result when the test is being skipped#21944
Tabrizian wants to merge 1 commit intopython:mainfrom
Tabrizian:patch-1

Conversation

@Tabrizian
Copy link
Copy Markdown
Contributor

@Tabrizian Tabrizian commented Aug 23, 2020

Currently unittest does not return TestResult object when the test is skipped.

https://bugs.python.org/issue41620

@the-knights-who-say-ni
Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@Tabrizian

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@Tabrizian Tabrizian changed the title Return the result when the test is being skipped bpo-41620: Return the result when the test is being skipped Aug 23, 2020
@Tabrizian
Copy link
Copy Markdown
Contributor Author

Fixed the CLA and created a bug report. Also, opened an account in bugs.python.org.

@iritkatriel
Copy link
Copy Markdown
Member

(1) Why is the result useful when no test was executed?
(2) This PR is missing a test.

@Tabrizian
Copy link
Copy Markdown
Contributor Author

Tabrizian commented Aug 23, 2020

  1. The problem is that when I'm trying to collect test results if one of the tests is being skipped the error below pops up because test_result object is None.
AttributeError: 'NoneType' object has no attribute 'testsRun'
import unittest 
import json


class TestResultCollector(unittest.TestCase):

    @classmethod
    def setResult(cls, total, errors, failures):
        cls.total, cls.errors, cls.failures = \
                total, errors, failures

    @classmethod
    def tearDownClass(cls):
        json_res = {
                'total': cls.total,
                'errors': cls.errors,
                'failures': cls.failures
                }
        print(json.dumps(json_res))

    def test1(self):
        self.assertTrue(True)

    def test2(self):
        self.assertTrue(True) 

    def test3(self):
        self.assertTrue(True)

    @unittest.skip('Skip Test')
    def test4(self):
        self.assertTrue(True)

    def run(self, result=None): 
        test_result = super().run(result)
        total = test_result.testsRun
        errors = len(test_result.errors)
        failures = len(test_result.failures)
        self.setResult(total, errors, failures)

if __name__ == '__main__':
        unittest.main()
  1. I will add a unittest for this test case if you think this is a valid change. @iritkatriel

@serhiy-storchaka
Copy link
Copy Markdown
Member

I think it is a valid change. Please resolve conflicts and add tests.

@ambv
Copy link
Copy Markdown
Contributor

ambv commented Aug 30, 2021

Closing in favor of GH-28030.

@ambv ambv closed this Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants