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

self._outcome.errors no longer contains error data since pytest 5.4.0 #7000

Closed
mdmintz opened this issue Apr 2, 2020 · 6 comments
Closed
Labels
plugin: unittest related to the unittest integration builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Milestone

Comments

@mdmintz
Copy link

mdmintz commented Apr 2, 2020

self._outcome.errors no longer contains error data since pytest 5.4.0

My test framework uses pytest to run tests that use a unittest.TestCase structure, and in the tearDown() method I was able to get error output from failing tests by using:
self._outcome.errors
This was working fine with pytest 5.3.5, but stopped working with pytest 5.4.0

This technique was made possible by this very popular solution on Stack Overflow: https://stackoverflow.com/a/39606065

Here's a code snippet that uses this technique to get the error from the tearDown() step when a test fails an assertion:

import unittest

class MyTest(unittest.TestCase):

    def tearDown(self):
        if hasattr(self, '_outcome'):
            errors = self._outcome.errors
            ...

I would like pytest to restore the use of self._outcome.errors so that tearDown() methods can easily access the error output of tests.
The test framework that I'm using (which I've built) is called SeleniumBase => https://github.com/seleniumbase/SeleniumBase
My workaround for now has been to hard-code pytest 5.3.5 into the requirements file for SeleniumBase. Given the large number of companies using SeleniumBase for test automation, I have to keep things working while waiting for a fix to arrive.

@Zac-HD Zac-HD added the type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature label Apr 2, 2020
@Zac-HD
Copy link
Member

Zac-HD commented Apr 2, 2020

(I've tagged this as a proposal, because accessing a private attribute is almost the definition of unsupported. If it doesn't make anything else worse we'd probably accept a PR to restore the old behaviour, but no promises that it wouldn't get changed again later...)

@RonnyPfannschmidt
Copy link
Member

this is a unittest internal, it should be available, i believe this is part of why teadown currently fails

@RonnyPfannschmidt RonnyPfannschmidt added plugin: unittest related to the unittest integration builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously labels Apr 2, 2020
@RonnyPfannschmidt RonnyPfannschmidt added this to the 5.4.2 milestone Apr 2, 2020
@RonnyPfannschmidt RonnyPfannschmidt removed the type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature label Apr 2, 2020
@blueyed
Copy link
Contributor

blueyed commented Apr 2, 2020

@RonnyPfannschmidt teardown is skipped, which includes unittest feeding the errors.
I think this should be clear, isn't it?

@mdmintz
Copy link
Author

mdmintz commented Apr 3, 2020

@RonnyPfannschmidt , @blueyed , I created a test that'll pass when this issue is fixed. You'll be able to use it to determine which commit broke the functionality. It passes on 5.3.5 and fails on 5.4.0. There's a commit somewhere in between that broke things.

def test_outcome_errors(testdir):
    testpath = testdir.makepyfile(
        """
        import unittest
        class MyTestCase(unittest.TestCase):
            def test_fail(self):
                raise Exception("FAIL!")
            def tearDown(self):
                print(self._outcome.errors)
    """
    )
    reprec = testdir.inline_run(testpath)
    passed, skipped, failed = reprec.countoutcomes()
    assert failed == 1, failed

@mdmintz
Copy link
Author

mdmintz commented Apr 3, 2020

@blueyed
Copy link
Contributor

blueyed commented Apr 3, 2020

@mdmintz
Thanks, the issue is known already: #6947
(as mentioned in seleniumbase/SeleniumBase#534 (comment) already). Closing as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: unittest related to the unittest integration builtin plugin type: bug problem that needs to be addressed type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

4 participants