Expose exception_from_error_queue in the most inelegant way; use this in the base TestCase to make sure no tests leave garbage errors lying around
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index 7a4228d..89d7e5e 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -535,6 +535,17 @@
     return PyString_FromString(str);
 }
 
+static char crypto_exception_from_error_queue_doc[] = "\n\
+Raise an exception from the current OpenSSL error queue.\n\
+";
+
+static PyObject *
+crypto_exception_from_error_queue(PyObject *spam, PyObject *eggs) {
+    exception_from_error_queue(crypto_Error);
+    return NULL;
+}
+
+
 /* Methods in the OpenSSL.crypto module (i.e. none) */
 static PyMethodDef crypto_methods[] = {
     /* Module functions */
@@ -547,6 +558,7 @@
     { "load_pkcs7_data", (PyCFunction)crypto_load_pkcs7_data, METH_VARARGS, crypto_load_pkcs7_data_doc },
     { "load_pkcs12", (PyCFunction)crypto_load_pkcs12, METH_VARARGS, crypto_load_pkcs12_doc },
     { "X509_verify_cert_error_string", (PyCFunction)crypto_X509_verify_cert_error_string, METH_VARARGS, crypto_X509_verify_cert_error_string_doc },
+    { "_exception_from_error_queue", (PyCFunction)crypto_exception_from_error_queue, METH_NOARGS, crypto_exception_from_error_queue_doc },
     { NULL, NULL }
 };
 
diff --git a/test/util.py b/test/util.py
index fdc9348..3d47c28 100644
--- a/test/util.py
+++ b/test/util.py
@@ -30,7 +30,13 @@
                     shutil.rmtree(temp)
                 elif os.path.exists(temp):
                     os.unlink(temp)
-        
+        from OpenSSL.crypto import Error, _exception_from_error_queue
+        try:
+            _exception_from_error_queue()
+        except Error, e:
+            if e.args != ([],):
+                self.fail("Left over errors in OpenSSL error queue: " + repr(e))
+
 
     def failUnlessIdentical(self, first, second, msg=None):
         """