python: collect: ignore exceptions with isinstance

Fixes https://github.com/pytest-dev/pytest/issues/4266.
This commit is contained in:
Daniel Hahler
2018-11-01 00:54:48 +01:00
parent 56e6bb0ff6
commit e30f7094f3
6 changed files with 74 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
import sys
import six
import pytest
from _pytest.outcomes import Failed
@@ -170,3 +172,25 @@ class TestRaises(object):
Failed, match="DID NOT RAISE <class 'raises.ClassLooksIterableException'>"
):
pytest.raises(ClassLooksIterableException, lambda: None)
def test_raises_with_raising_dunder_class(self):
"""Test current behavior with regard to exceptions via __class__ (#4284)."""
class CrappyClass(Exception):
@property
def __class__(self):
assert False, "via __class__"
if six.PY2:
with pytest.raises(pytest.fail.Exception) as excinfo:
with pytest.raises(CrappyClass()):
pass
assert "DID NOT RAISE" in excinfo.value.args[0]
with pytest.raises(CrappyClass) as excinfo:
raise CrappyClass()
else:
with pytest.raises(AssertionError) as excinfo:
with pytest.raises(CrappyClass()):
pass
assert "via __class__" in excinfo.value.args[0]