Skip to content

Commit

Permalink
Merge pull request #20012 from eric-wieser/remove-xfail
Browse files Browse the repository at this point in the history
Fix sympy.testing.pytest.raises to behave like pytest.raises
  • Loading branch information
eric-wieser committed Sep 2, 2020
2 parents e27894d + 5ff9c4b commit 7f57339
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 1 addition & 3 deletions sympy/multipledispatch/tests/test_core.py
Expand Up @@ -2,7 +2,7 @@

from sympy.multipledispatch import dispatch
from sympy.multipledispatch.conflict import AmbiguityWarning
from sympy.testing.pytest import raises, XFAIL, warns
from sympy.testing.pytest import raises, warns
from functools import partial

test_namespace = dict() # type: Dict[str, Any]
Expand All @@ -11,7 +11,6 @@
dispatch = partial(dispatch, namespace=test_namespace)


@XFAIL
def test_singledispatch():
@dispatch(int)
def f(x): # noqa:F811
Expand Down Expand Up @@ -66,7 +65,6 @@ def f(x): # noqa:F811
assert f(C()) == 'a'


@XFAIL
def test_inheritance_and_multiple_dispatch():
@dispatch(A, A)
def f(x, y): # noqa:F811
Expand Down
8 changes: 1 addition & 7 deletions sympy/multipledispatch/tests/test_dispatcher.py
@@ -1,7 +1,7 @@
from sympy.multipledispatch.dispatcher import (Dispatcher, MDNotImplementedError,
MethodDispatcher, halt_ordering,
restart_ordering)
from sympy.testing.pytest import raises, XFAIL, warns
from sympy.testing.pytest import raises, warns


def identity(x):
Expand Down Expand Up @@ -88,7 +88,6 @@ def on_ambiguity(dispatcher, amb):
assert ambiguities[0]


@XFAIL
def test_raise_error_on_non_class():
f = Dispatcher('f')
assert raises(TypeError, lambda: f.add((1,), inc))
Expand Down Expand Up @@ -165,7 +164,6 @@ def two(x, y):
assert 'x - y' in f._source(1.0, 1.0)


@XFAIL
def test_source_raises_on_missing_function():
f = Dispatcher('f')

Expand Down Expand Up @@ -197,13 +195,11 @@ def func(*args):
assert set(f.ordering) == {(int, object), (object, int)}


@XFAIL
def test_no_implementations():
f = Dispatcher('f')
assert raises(NotImplementedError, lambda: f('hello'))


@XFAIL
def test_register_stacking():
f = Dispatcher('f')

Expand Down Expand Up @@ -238,7 +234,6 @@ class MyList(list):
assert f.dispatch(int, int) is add


@XFAIL
def test_not_implemented():
f = Dispatcher('f')

Expand All @@ -259,7 +254,6 @@ def _(x):
assert raises(NotImplementedError, lambda: f(1, 2))


@XFAIL
def test_not_implemented_error():
f = Dispatcher('f')

Expand Down
14 changes: 12 additions & 2 deletions sympy/testing/pytest.py
Expand Up @@ -34,6 +34,15 @@
# Not using pytest so define the things that would have been imported from
# there.

# _pytest._code.code.ExceptionInfo
class ExceptionInfo:
def __init__(self, value):
self.value = value

def __repr__(self):
return "<ExceptionInfo {!r}>".format(self.value)


def raises(expectedException, code=None):
"""
Tests that ``code`` raises the exception ``expectedException``.
Expand All @@ -54,6 +63,7 @@ def raises(expectedException, code=None):
>>> from sympy.testing.pytest import raises
>>> raises(ZeroDivisionError, lambda: 1/0)
<ExceptionInfo ZeroDivisionError(...)>
>>> raises(ZeroDivisionError, lambda: 1/2)
Traceback (most recent call last):
...
Expand Down Expand Up @@ -92,8 +102,8 @@ def raises(expectedException, code=None):
elif callable(code):
try:
code()
except expectedException:
return
except expectedException as e:
return ExceptionInfo(e)
raise Failed("DID NOT RAISE")
elif isinstance(code, str):
raise TypeError(
Expand Down

0 comments on commit 7f57339

Please sign in to comment.