diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index bd02f680401420cca03ba4a9933fad4c2f8aa582..84e3ef024721e9812d4b7e502a09eb440853dd83 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -535,17 +535,17 @@ def test_hamiltonian_evaluation(): def test_raising(fsyst, hop): a, b = hop # exceptions are converted to kwant.UserCodeError and we add our message - with raises(kwant.UserCodeError) as ctx: + with raises(kwant.UserCodeError) as exc_info: fsyst.hamiltonian(a, a) msg = 'Error occurred in user-supplied value function "onsite_raises"' - assert msg in ctx.exconly() + assert msg in str(exc_info.value) for hop in [(a, b), (b, a)]: - with raises(kwant.UserCodeError) as ctx: + with raises(kwant.UserCodeError) as exc_info: fsyst.hamiltonian(*hop) msg = ('Error occurred in user-supplied ' 'value function "hopping_raises"') - assert msg in ctx.exconly() + assert msg in str(exc_info.value) # test with finite system new_hop = (fam(-1, 0), fam(0, 0)) diff --git a/kwant/tests/test_operator.py b/kwant/tests/test_operator.py index 6eb0e631a3d0794846bbd078898a27b4c829cab4..f6e5271ba658e683ac5a2e02abf3c3ba311de61f 100644 --- a/kwant/tests/test_operator.py +++ b/kwant/tests/test_operator.py @@ -425,14 +425,14 @@ def test_arg_passing(A): # test missing params op = A(fsyst, onsite=lambda x, a, b: 1) params = dict(a=1) - with raises(TypeError) as exc: + with raises(TypeError): op(wf, params=params) - with raises(TypeError) as exc: + with raises(TypeError): op.act(wf, params=params) - with raises(TypeError) as exc: + with raises(TypeError): op.bind(params=params) if hasattr(op, 'tocoo'): - with raises(TypeError) as exc: + with raises(TypeError): op.tocoo(params=params) @@ -445,19 +445,19 @@ def test_arg_passing(A): if has_tocoo: tocoo_should_be = op.tocoo(args=canonical_args).toarray() - with raises(TypeError) as exc: + with raises(TypeError) as exc_info: op(wf, args=canonical_args, params=params) - assert 'mutually exclusive' in str(exc) - with raises(TypeError) as exc: + assert 'mutually exclusive' in str(exc_info.value) + with raises(TypeError) as exc_info: op.act(wf, args=canonical_args, params=params) - assert 'mutually exclusive' in str(exc) - with raises(TypeError) as exc: + assert 'mutually exclusive' in str(exc_info.value) + with raises(TypeError) as exc_info: op.bind(args=canonical_args, params=params) - assert 'mutually exclusive' in str(exc) + assert 'mutually exclusive' in str(exc_info.value) if has_tocoo: - with raises(TypeError) as exc: + with raises(TypeError) as exc_info: op.tocoo(args=canonical_args, params=params) - assert 'mutually exclusive' in str(exc) + assert 'mutually exclusive' in str(exc_info.value) np.testing.assert_array_equal( call_should_be, op(wf, params=params))