Add a test for the error case of setattr
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index a3f30d9..65bc8e8 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -245,8 +245,7 @@
         add_result = _lib.X509_NAME_add_entry_by_NID(
             self._name, nid, _lib.MBSTRING_UTF8, value, -1, -1, 0)
         if not add_result:
-            # TODO Untested
-            1/0
+            _raise_current_error()
 
 
     def __getattr__(self, name):
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 2acf339..d451c9c 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -737,6 +737,7 @@
         self.assertRaises(TypeError, setattr, name, None, "hello")
         self.assertRaises(TypeError, setattr, name, 30, "hello")
 
+
     def test_setInvalidAttribute(self):
         """
         Attempting to set any attribute name on an :py:class:`X509NameType` instance for
@@ -926,6 +927,16 @@
             "null.python.org\x00example.org", subject.commonName)
 
 
+    def test_setAttributeFailure(self):
+        """
+        If the value of an attribute cannot be set for some reason then
+        :py:class:`OpenSSL.crypto.Error` is raised.
+        """
+        name = self._x509name()
+        # This value is too long
+        self.assertRaises(Error, setattr, name, "O", b"x" * 512)
+
+
 
 class _PKeyInteractionTestsMixin:
     """
@@ -2938,6 +2949,7 @@
         self.assertRaises(Error, load_crl, FILETYPE_PEM, "hello, world")
 
 
+
 class SignVerifyTests(TestCase):
     """
     Tests for :py:obj:`OpenSSL.crypto.sign` and :py:obj:`OpenSSL.crypto.verify`.