-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Catch BaseException in safe_getattr #2707
Catch BaseException in safe_getattr #2707
Conversation
this change would make it ignore |
from what i can tell this is a compound issue and both solutions are incorrect, i'd like to defer that one to @hpk42 |
12e2cd6
to
ad00303
Compare
After writting down the issue I've figured out minimal reproducible script import pytest
from unittest import TestCase
class SomeDescriptor:
def __init__(self, fun):
self.fun = fun
def __get__(self, obj, cls=None):
self.fun(cls)
def exc_fun(cls):
if cls.fail:
raise pytest.fail('Hello Exception')
print('\ncalled exc_fun')
@pytest.fixture(autouse=True, scope='class')
def _runtest_setup(request):
request.node.cls.fail = False
request.node.cls.exc_prop
class TestException(TestCase):
fail = True
exc_prop = SomeDescriptor(exc_fun)
def test_something(self):
pass @RonnyPfannschmidt yeah, sure we should catch it as TEST_OUTCOMES to prevent other errors from being catched (updated it) |
well done @cybergrind the new iteration looks correct 👍 a unitest is needed, checking that a simple declared property that causes a test failure and a test getting it should fit to test the behaviour for completeness sake there should be a extension of the docstring telling it will catch exceptions and |
ad00303
to
d9c3d7e
Compare
d9c3d7e
to
12b1bff
Compare
hey, @RonnyPfannschmidt |
@cybergrind sorry for the wait |
Reopening to see how it fares with the latest hypothesis, this problem was fixed in |
Also took the liberty of improving the changelog a bit to be more user-friendly about the problem description. |
thanks everyone 👍 |
Hey, all!
Today I've spent few hours by tracking strange error after update to 3.2.1
git blaming
showed that it was caused by 06a4933 from #2490 (that is fix for #580 ) particularly inheritance fromBaseException
@nicoddemus @RonnyPfannschmidt
This is quite hard to provide minimal steps to reproduce our case, in general it is caused by https://github.com/pytest-dev/pytest-django/blob/master/pytest_django/plugin.py#L615 throws
fail
We're doing some work during class initialization (in descriptors), thus before database is unblocked and it was fine before this commit: upon collecting it wasn't fail and during the tests, fixtures were created without errors.
safe_getattr
isn't catching error, because new fail exception is derived from BaseExceptionI believe we shouldn't fail during
collecting
phase, so either:safe_getattr
to catch BaseExceptionsafe_getattr
realization inFixtureManager.parsefactories
This PR contains 1st as simplest but I can reimplement it to 2nd