Use pytest.raises() instead of try/catch with asser 0

This is somehow more readable, and enable using the features of pytest's ExeptionInfo (such as errisinstance).
This commit is contained in:
Reuven 2016-03-04 13:30:40 +02:00
parent e7d548595e
commit 4dc2ef19ea
5 changed files with 39 additions and 84 deletions

View file

@ -100,13 +100,10 @@ def test_session_transactions_no_null_sessions():
app.testing = True
with app.test_client() as c:
try:
with pytest.raises(RuntimeError) as e:
with c.session_transaction() as sess:
pass
except RuntimeError as e:
assert 'Session backend did not open a session' in str(e)
else:
assert False, 'Expected runtime error'
assert 'Session backend did not open a session' in str(e.value)
def test_session_transactions_keep_context():
app = flask.Flask(__name__)
@ -124,13 +121,10 @@ def test_session_transaction_needs_cookies():
app = flask.Flask(__name__)
app.testing = True
c = app.test_client(use_cookies=False)
try:
with pytest.raises(RuntimeError) as e:
with c.session_transaction() as s:
pass
except RuntimeError as e:
assert 'cookies' in str(e)
else:
assert False, 'Expected runtime error'
assert 'cookies' in str(e.value)
def test_test_client_context_binding():
app = flask.Flask(__name__)