def test_ports_fail(self): s1 = NetlinkSocket(port=0x10) s2 = NetlinkSocket(port=0x10) # check if ports are set assert s1.port == s2.port # bind the first socket, must succeed s1.bind() # bind the second, must fail try: s2.bind() except socket.error as e: # but it must fail only with errno == 98 if e.errno == 98: pass # check the first socket is bound assert s1.getsockname()[0] != 0 # check the second socket is not bound assert s2.getsockname()[0] == 0 s1.close()