Merge branch 'master' into clean-up-test-runner
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 6c2019b..cde8167 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -2152,10 +2152,10 @@
         :py:obj:`Connection.connect` raises :py:obj:`TypeError` if called with a non-address
         argument or with the wrong number of arguments.
         """
-        
+
         def attr_access_test(connection):
             return connection.an_attribute_which_is_not_defined
-        
+
         connection = Connection(Context(TLSv1_METHOD), None)
         self.assertRaises(AttributeError, attr_access_test, connection)
 
@@ -2167,9 +2167,11 @@
         client = socket()
         context = Context(TLSv1_METHOD)
         clientSSL = Connection(context, client)
-        exc = self.assertRaises(error, clientSSL.connect, ("127.0.0.1", 1))
-        self.assertEquals(exc.args[0], ECONNREFUSED)
-
+        try:
+            clientSSL.connect(("127.0.0.1", 1))
+        except error as e:
+            pass
+        assert e.args[0] == ECONNREFUSED
 
     def test_connect(self):
         """
diff --git a/OpenSSL/test/util.py b/OpenSSL/test/util.py
index 8b034dc..7f6f38c 100644
--- a/OpenSSL/test/util.py
+++ b/OpenSSL/test/util.py
@@ -14,6 +14,8 @@
 from tempfile import mktemp, mkdtemp
 from unittest import TestCase
 
+import pytest
+
 from six import PY3
 
 from OpenSSL._util import exception_from_error_queue
@@ -200,13 +202,7 @@
         @param message: Custom text to include in the exception text if the
             assertion fails.
         """
-        if not isinstance(instance, classOrTuple):
-            if message is None:
-                suffix = ""
-            else:
-                suffix = ": " + message
-            self.fail("%r is not an instance of %s%s" % (
-                instance, classOrTuple, suffix))
+        assert isinstance(instance, classOrTuple)
 
     def failUnlessIn(self, containee, container, msg=None):
         """
@@ -218,10 +214,7 @@
         :param msg: if msg is None, then the failure message will be
                     '%r not in %r' % (first, second)
         """
-        if containee not in container:
-            raise self.failureException(msg or "%r not in %r"
-                                        % (containee, container))
-        return containee
+        assert containee in container
     assertIn = failUnlessIn
 
     def assertNotIn(self, containee, container, msg=None):
@@ -234,10 +227,7 @@
         @param msg: if msg is None, then the failure message will be
                     '%r in %r' % (first, second)
         """
-        if containee in container:
-            raise self.failureException(msg or "%r in %r"
-                                        % (containee, container))
-        return containee
+        assert containee not in container
     failIfIn = assertNotIn
 
     def assertIs(self, first, second, msg=None):
@@ -249,9 +239,7 @@
         :param msg: if msg is None, then the failure message will be
         '%r is not %r' % (first, second)
         """
-        if first is not second:
-            raise self.failureException(msg or '%r is not %r' % (first, second))
-        return first
+        assert first is second
     assertIdentical = failUnlessIdentical = assertIs
 
     def assertIsNot(self, first, second, msg=None):
@@ -263,9 +251,7 @@
         :param msg: if msg is None, then the failure message will be
         '%r is %r' % (first, second)
         """
-        if first is second:
-            raise self.failureException(msg or '%r is %r' % (first, second))
-        return first
+        assert first is not second
     assertNotIdentical = failIfIdentical = assertIsNot
 
     def failUnlessRaises(self, exception, f, *args, **kwargs):
@@ -283,19 +269,9 @@
             not raise an exception or if it raises an exception of a
             different type.
         """
-        try:
-            result = f(*args, **kwargs)
-        except exception:
-            inst = sys.exc_info()[1]
-            return inst
-        except:
-            raise self.failureException('%s raised instead of %s'
-                                        % (sys.exc_info()[0],
-                                           exception.__name__,
-                                           ))
-        else:
-            raise self.failureException('%s not raised (%r returned)'
-                                        % (exception.__name__, result))
+        with pytest.raises(exception) as cm:
+            f(*args, **kwargs)
+        return cm.value
     assertRaises = failUnlessRaises
 
     def mktemp(self):