Closed
Description
I don't know how to describe this, so here's a minimal test case:
import errno
import socket
import pytest
def test_foo():
s = socket.socket()
with pytest.raises(socket.error) as cm:
s.connect(("127.0.0.1", 1))
assert cm.value.errno == errno.ECONNREFUSED
and this fails with:
====================================================== test session starts =======================================================
platform darwin -- Python 2.6.9 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/alex_gaynor/.virtualenvs/tempenv-39fb22646f9f, inifile:
collected 1 items
test.py F
============================================================ FAILURES ============================================================
____________________________________________________________ test_foo ____________________________________________________________
def test_foo():
s = socket.socket()
with pytest.raises(socket.error) as cm:
s.connect(("127.0.0.1", 1))
> assert cm.value.errno == errno.ECONNREFUSED
E assert None == 61
E + where None = error((61, 'Connection refused'),).errno
E + where error((61, 'Connection refused'),) = <ExceptionInfo error tblen=2>.value
E + and 61 = errno.ECONNREFUSED
test.py:11: AssertionError
==================================================== 1 failed in 0.01 seconds ====================================================
if you just use a normal try
/ except
you get an exception with a correct errno