diff --git a/CHANGES.rst b/CHANGES.rst
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_Q0hBTkdFUy5yc3Q=..939e5020b70e488704c674e765288ac585812de6_Q0hBTkdFUy5yc3Q= 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,6 +5,6 @@
 - Forward-referencing ASN.1 types implemented to handle
   the case of recursive ASN.1 schemas.
 
-Revision 0.3.4, released XX-08-2017
+Revision 0.3.5, released 16-09-2017
 -----------------------------------
 
@@ -9,7 +9,16 @@
 -----------------------------------
 
-- Forward-referencing ASN.1 types implemented to handle
-  the case of recursive ASN.1 schemas.
+- Codecs signatures unified and pass the options kwargs through the
+  call chain
+- Explicit tag encoding optimized to avoid unnecessary copying
+- End-of-octets sentinel encoding optimized
+- Refactored ASN.1 codecs properties to silently enforce proper
+  length and chunk size encoding modes
+- Fixed DER encoder to always produce primitive encoding
+- Fixed crash at SequenceOf native decoder
+- Fixed Real.prettyPrint() to fail gracefully on overflow
+- Fixed a couple of crashes when debug mode is enabled
+>>>>>>> devel-0.4.1
 
 Revision 0.3.4, released 07-09-2017
 -----------------------------------
diff --git a/doc/source/docs/api-reference.rst b/doc/source/docs/api-reference.rst
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_ZG9jL3NvdXJjZS9kb2NzL2FwaS1yZWZlcmVuY2UucnN0..939e5020b70e488704c674e765288ac585812de6_ZG9jL3NvdXJjZS9kb2NzL2FwaS1yZWZlcmVuY2UucnN0 100644
--- a/doc/source/docs/api-reference.rst
+++ b/doc/source/docs/api-reference.rst
@@ -16,6 +16,7 @@
    /docs/type/useful/contents
    /docs/type/tag/contents
    /docs/type/namedtype/contents
+   /docs/type/opentype/contents
    /docs/type/namedval/contents
 
 Transformation codecs
diff --git a/doc/source/docs/type/opentype/contents.rst b/doc/source/docs/type/opentype/contents.rst
new file mode 100644
index 0000000000000000000000000000000000000000..939e5020b70e488704c674e765288ac585812de6_ZG9jL3NvdXJjZS9kb2NzL3R5cGUvb3BlbnR5cGUvY29udGVudHMucnN0
--- /dev/null
+++ b/doc/source/docs/type/opentype/contents.rst
@@ -0,0 +1,8 @@
+
+Untyped fields of constructed types
+-----------------------------------
+
+.. toctree::
+   :maxdepth: 2
+
+   /docs/type/opentype/opentype
diff --git a/doc/source/docs/type/opentype/opentype.rst b/doc/source/docs/type/opentype/opentype.rst
new file mode 100644
index 0000000000000000000000000000000000000000..939e5020b70e488704c674e765288ac585812de6_ZG9jL3NvdXJjZS9kb2NzL3R5cGUvb3BlbnR5cGUvb3BlbnR5cGUucnN0
--- /dev/null
+++ b/doc/source/docs/type/opentype/opentype.rst
@@ -0,0 +1,14 @@
+
+.. |OpenType| replace:: OpenType
+
+|OpenType|
+-----------
+
+.. autoclass:: pyasn1.type.opentype.OpenType
+   :members:
+
+   .. note::
+
+        The |OpenType| class models an untyped field of a constructed ASN.1
+        type. In ASN.1 syntax it is usually represented by the
+        `ANY DEFINED BY` clause.
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL2Jlci9kZWNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL2Jlci9kZWNvZGVyLnB5 100644
--- a/pyasn1/codec/ber/decoder.py
+++ b/pyasn1/codec/ber/decoder.py
@@ -18,7 +18,9 @@
 class AbstractDecoder(object):
     protoComponent = None
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         raise error.PyAsn1Error('Decoder not implemented for %s' % (tagSet,))
 
@@ -23,7 +25,9 @@
         raise error.PyAsn1Error('Decoder not implemented for %s' % (tagSet,))
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         raise error.PyAsn1Error('Indefinite length mode decoder not implemented for %s' % (tagSet,))
 
 
@@ -44,10 +48,12 @@
 class ExplicitTagDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Any('')
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         if substrateFun:
             return substrateFun(
                 self._createComponent(asn1Spec, tagSet, ''),
                 substrate, length
             )
@@ -49,6 +55,7 @@
         if substrateFun:
             return substrateFun(
                 self._createComponent(asn1Spec, tagSet, ''),
                 substrate, length
             )
+
         head, tail = substrate[:length], substrate[length:]
@@ -54,4 +61,6 @@
         head, tail = substrate[:length], substrate[length:]
-        value, _ = decodeFun(head, asn1Spec, tagSet, length)
+
+        value, _ = decodeFun(head, asn1Spec, tagSet, length, **options)
+
         return value, tail
 
@@ -56,9 +65,11 @@
         return value, tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         if substrateFun:
             return substrateFun(
                 self._createComponent(asn1Spec, tagSet, ''),
                 substrate, length
             )
@@ -60,11 +71,14 @@
         if substrateFun:
             return substrateFun(
                 self._createComponent(asn1Spec, tagSet, ''),
                 substrate, length
             )
-        value, substrate = decodeFun(substrate, asn1Spec, tagSet, length)
-        terminator, substrate = decodeFun(substrate, allowEoo=True)
-        if terminator is eoo.endOfOctets:
+
+        value, substrate = decodeFun(substrate, asn1Spec, tagSet, length, **options)
+
+        eooMarker, substrate = decodeFun(substrate, allowEoo=True, **options)
+
+        if eooMarker is eoo.endOfOctets:
             return value, substrate
         else:
             raise error.PyAsn1Error('Missing end-of-octets terminator')
@@ -76,8 +90,10 @@
 class IntegerDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Integer(0)
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
-                     state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
 
         if tagSet[0].tagFormat != tag.tagFormatSimple:
             raise error.PyAsn1Error('Simple tag format expected')
@@ -103,8 +119,10 @@
     protoComponent = univ.BitString(())
     supportConstructedForm = True
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
-                     state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         head, tail = substrate[:length], substrate[length:]
         if tagSet[0].tagFormat == tag.tagFormatSimple:  # XXX what tag to check?
             if not head:
@@ -127,8 +145,8 @@
             return substrateFun(bitString, substrate, length)
 
         while head:
-            component, head = decodeFun(head, self.protoComponent)
+            component, head = decodeFun(head, self.protoComponent, **options)
             bitString += component
 
         return bitString, tail
 
@@ -131,12 +149,14 @@
             bitString += component
 
         return bitString, tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         bitString = self._createComponent(asn1Spec, tagSet)
 
         if substrateFun:
             return substrateFun(bitString, substrate, length)
 
         while substrate:
@@ -137,10 +157,11 @@
         bitString = self._createComponent(asn1Spec, tagSet)
 
         if substrateFun:
             return substrateFun(bitString, substrate, length)
 
         while substrate:
-            component, substrate = decodeFun(substrate, self.protoComponent, allowEoo=True)
+            component, substrate = decodeFun(substrate, self.protoComponent,
+                                             allowEoo=True, **options)
             if component is eoo.endOfOctets:
                 break
 
@@ -156,8 +177,10 @@
     protoComponent = univ.OctetString('')
     supportConstructedForm = True
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
-                     state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         head, tail = substrate[:length], substrate[length:]
 
         if substrateFun:
@@ -177,8 +200,9 @@
 
         while head:
             component, head = decodeFun(head, self.protoComponent,
-                                        substrateFun=substrateFun)
+                                        substrateFun=substrateFun,
+                                        **options)
             header += component
 
         return self._createComponent(asn1Spec, tagSet, header), tail
 
@@ -181,9 +205,11 @@
             header += component
 
         return self._createComponent(asn1Spec, tagSet, header), tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         if substrateFun and substrateFun is not self.substrateCollector:
             asn1Object = self._createComponent(asn1Spec, tagSet)
             return substrateFun(asn1Object, substrate, length)
@@ -197,7 +223,7 @@
             component, substrate = decodeFun(substrate,
                                              self.protoComponent,
                                              substrateFun=substrateFun,
-                                             allowEoo=True)
+                                             allowEoo=True, **options)
             if component is eoo.endOfOctets:
                 break
             header += component
@@ -205,9 +231,10 @@
             raise error.SubstrateUnderrunError(
                 'No EOO seen before substrate ends'
             )
+
         return self._createComponent(asn1Spec, tagSet, header), substrate
 
 
 class NullDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Null('')
 
@@ -208,11 +235,13 @@
         return self._createComponent(asn1Spec, tagSet, header), substrate
 
 
 class NullDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Null('')
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
 
         if tagSet[0].tagFormat != tag.tagFormatSimple:
             raise error.PyAsn1Error('Simple tag format expected')
@@ -230,9 +259,10 @@
 class ObjectIdentifierDecoder(AbstractSimpleDecoder):
     protoComponent = univ.ObjectIdentifier(())
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
-                     state, decodeFun, substrateFun):
-
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         if tagSet[0].tagFormat != tag.tagFormatSimple:
             raise error.PyAsn1Error('Simple tag format expected')
 
@@ -286,8 +316,10 @@
 class RealDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Real()
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         if tagSet[0].tagFormat != tag.tagFormatSimple:
             raise error.PyAsn1Error('Simple tag format expected')
 
@@ -371,7 +403,7 @@
     def _getComponentPositionByType(self, asn1Object, tagSet, idx):
         raise NotImplementedError()
 
-    def _decodeComponents(self, substrate, decodeFun, tagSet, allowEoo=True):
+    def _decodeComponents(self, substrate, tagSet=None, decodeFun=None, **options):
         components = []
         componentTypes = set()
         while substrate:
@@ -375,7 +407,7 @@
         components = []
         componentTypes = set()
         while substrate:
-            component, substrate = decodeFun(substrate, allowEoo=True)
+            component, substrate = decodeFun(substrate, **options)
             if component is eoo.endOfOctets:
                 break
             components.append(component)
@@ -406,8 +438,10 @@
 
         return asn1Object, substrate
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         if tagSet[0].tagFormat != tag.tagFormatConstructed:
             raise error.PyAsn1Error('Constructed tag format expected')
 
@@ -424,7 +458,9 @@
             return substrateFun(asn1Object, substrate, length)
 
         if asn1Spec is None:
-            asn1Object, trailing = self._decodeComponents(head, decodeFun, tagSet)
+            asn1Object, trailing = self._decodeComponents(
+                head, tagSet=tagSet, decodeFun=decodeFun, **options
+            )
             if trailing:
                 raise error.PyAsn1Error('Unused trailing %d octets encountered' % len(trailing))
             return asn1Object, tail
@@ -455,6 +491,6 @@
                             asn1Spec = namedTypes[idx].asn1Object
                     except IndexError:
                         raise error.PyAsn1Error(
-                            'Excessive components decoded at %r'(asn1Object,)
+                            'Excessive components decoded at %r' % (asn1Object,)
                         )
 
@@ -459,6 +495,6 @@
                         )
 
-                component, head = decodeFun(head, asn1Spec)
+                component, head = decodeFun(head, asn1Spec, **options)
 
                 if not isDeterministic and namedTypes:
                     if isSetType:
@@ -478,6 +514,43 @@
             if namedTypes:
                 if not namedTypes.requiredComponents.issubset(seenIndices):
                     raise error.PyAsn1Error('ASN.1 object %s has uninitialized components' % asn1Object.__class__.__name__)
+
+                if  namedTypes.hasOpenTypes:
+
+                    openTypes = options.get('openTypes', {})
+
+                    if openTypes or options.get('decodeOpenTypes', False):
+
+                        for idx, namedType in enumerate(namedTypes.namedTypes):
+                            if not namedType.openType:
+                                continue
+
+                            governingValue = asn1Object.getComponentByName(
+                                namedType.openType.name
+                            )
+
+                            try:
+                                asn1Spec = openTypes[governingValue]
+
+                            except KeyError:
+
+                                try:
+                                    asn1Spec = namedType.openType[governingValue]
+
+                                except KeyError:
+                                    continue
+
+                            component, rest = decodeFun(
+                                asn1Object.getComponentByPosition(idx).asOctets(),
+                                asn1Spec=asn1Spec
+                            )
+
+                            asn1Object.setComponentByPosition(
+                                idx, component,
+                                matchTags=False,
+                                matchConstraints=False
+                            )
+
             else:
                 asn1Object.verifySizeSpec()
 
@@ -485,7 +558,7 @@
             asn1Spec = asn1Object.componentType
             idx = 0
             while head:
-                component, head = decodeFun(head, asn1Spec)
+                component, head = decodeFun(head, asn1Spec, **options)
                 asn1Object.setComponentByPosition(
                     idx, component,
                     verifyConstraints=False,
@@ -493,7 +566,5 @@
                 )
                 idx += 1
 
-            asn1Object.verifySizeSpec()
-
         return asn1Object, tail
 
@@ -498,7 +569,9 @@
         return asn1Object, tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         if tagSet[0].tagFormat != tag.tagFormatConstructed:
             raise error.PyAsn1Error('Constructed tag format expected')
 
@@ -513,7 +586,9 @@
             return substrateFun(asn1Object, substrate, length)
 
         if asn1Spec is None:
-            return self._decodeComponents(substrate, decodeFun, tagSet, allowEoo=True)
+            return self._decodeComponents(
+                substrate, tagSet=tagSet, decodeFun=decodeFun, allowEoo=True, **options
+            )
 
         asn1Object = asn1Spec.clone()
 
@@ -544,7 +619,7 @@
                             'Excessive components decoded at %r' % (asn1Object,)
                         )
 
-                component, substrate = decodeFun(substrate, asn1Spec, allowEoo=True)
+                component, substrate = decodeFun(substrate, asn1Spec, allowEoo=True, **options)
                 if component is eoo.endOfOctets:
                     break
 
@@ -571,6 +646,44 @@
             if namedTypes:
                 if not namedTypes.requiredComponents.issubset(seenIndices):
                     raise error.PyAsn1Error('ASN.1 object %s has uninitialized components' % asn1Object.__class__.__name__)
+
+                if  namedTypes.hasOpenTypes:
+
+                    openTypes = options.get('openTypes', None)
+
+                    if openTypes or options.get('decodeOpenTypes', False):
+
+                        for idx, namedType in enumerate(namedTypes.namedTypes):
+                            if not namedType.openType:
+                                continue
+
+                            governingValue = asn1Object.getComponentByName(
+                                namedType.openType.name
+                            )
+
+                            try:
+                                asn1Spec = openTypes[governingValue]
+
+                            except KeyError:
+
+                                try:
+                                    asn1Spec = namedType.openType[governingValue]
+
+                                except KeyError:
+                                    continue
+
+                            component, rest = decodeFun(
+                                asn1Object.getComponentByPosition(idx).asOctets(),
+                                asn1Spec=asn1Spec, allowEoo=True
+                            )
+
+                            if component is not eoo.endOfOctets:
+                                asn1Object.setComponentByPosition(
+                                    idx, component,
+                                    matchTags=False,
+                                    matchConstraints=False
+                                )
+
             else:
                 asn1Object.verifySizeSpec()
 
@@ -578,7 +691,7 @@
             asn1Spec = asn1Object.componentType
             idx = 0
             while substrate:
-                component, substrate = decodeFun(substrate, asn1Spec, allowEoo=True)
+                component, substrate = decodeFun(substrate, asn1Spec, allowEoo=True, **options)
                 if component is eoo.endOfOctets:
                     break
                 asn1Object.setComponentByPosition(
@@ -591,7 +704,6 @@
                 raise error.SubstrateUnderrunError(
                     'No EOO seen before substrate ends'
                 )
-            asn1Object.verifySizeSpec()
 
         return asn1Object, substrate
 
@@ -595,6 +707,7 @@
 
         return asn1Object, substrate
 
+
 class SequenceOrSequenceOfDecoder(UniversalConstructedTypeDecoder):
     protoRecordComponent = univ.Sequence()
     protoSequenceComponent = univ.SequenceOf()
@@ -625,8 +738,10 @@
 class ChoiceDecoder(AbstractConstructedDecoder):
     protoComponent = univ.Choice()
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         head, tail = substrate[:length], substrate[length:]
         if asn1Spec is None:
             asn1Object = self.protoComponent.clone(tagSet=tagSet)
@@ -636,7 +751,7 @@
             return substrateFun(asn1Object, substrate, length)
         if asn1Object.tagSet == tagSet:  # explicitly tagged Choice
             component, head = decodeFun(
-                head, asn1Object.componentTagMap
+                head, asn1Object.componentTagMap, **options
             )
         else:
             component, head = decodeFun(
@@ -640,7 +755,8 @@
             )
         else:
             component, head = decodeFun(
-                head, asn1Object.componentTagMap, tagSet, length, state
+                head, asn1Object.componentTagMap,
+                tagSet, length, state, **options
             )
         effectiveTagSet = component.effectiveTagSet
         asn1Object.setComponentByType(
@@ -651,8 +767,10 @@
         )
         return asn1Object, tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         if asn1Spec is None:
             asn1Object = self.protoComponent.clone(tagSet=tagSet)
         else:
@@ -660,5 +778,7 @@
         if substrateFun:
             return substrateFun(asn1Object, substrate, length)
         if asn1Object.tagSet == tagSet:  # explicitly tagged Choice
-            component, substrate = decodeFun(substrate, asn1Object.componentType.tagMapUnique)
+            component, substrate = decodeFun(
+                substrate, asn1Object.componentType.tagMapUnique, **options
+            )
             # eat up EOO marker
@@ -664,6 +784,8 @@
             # eat up EOO marker
-            eooMarker, substrate = decodeFun(substrate, allowEoo=True)
+            eooMarker, substrate = decodeFun(
+                substrate, allowEoo=True, **options
+            )
             if eooMarker is not eoo.endOfOctets:
                 raise error.PyAsn1Error('No EOO seen before substrate ends')
         else:
             component, substrate = decodeFun(
@@ -666,8 +788,9 @@
             if eooMarker is not eoo.endOfOctets:
                 raise error.PyAsn1Error('No EOO seen before substrate ends')
         else:
             component, substrate = decodeFun(
-                substrate, asn1Object.componentType.tagMapUnique, tagSet, length, state
+                substrate, asn1Object.componentType.tagMapUnique,
+                tagSet, length, state, **options
             )
         effectiveTagSet = component.effectiveTagSet
         asn1Object.setComponentByType(
@@ -682,6 +805,8 @@
 class AnyDecoder(AbstractSimpleDecoder):
     protoComponent = univ.Any()
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                     length, state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         if asn1Spec is None or asn1Spec is not None and tagSet != asn1Spec.tagSet:
@@ -687,4 +812,6 @@
         if asn1Spec is None or asn1Spec is not None and tagSet != asn1Spec.tagSet:
+            fullSubstrate = options['fullSubstrate']
+
             # untagged Any container, recover inner header substrate
             length += len(fullSubstrate) - len(substrate)
             substrate = fullSubstrate
@@ -688,6 +815,7 @@
             # untagged Any container, recover inner header substrate
             length += len(fullSubstrate) - len(substrate)
             substrate = fullSubstrate
+
         if substrateFun:
             return substrateFun(self._createComponent(asn1Spec, tagSet),
                                 substrate, length)
@@ -691,4 +819,5 @@
         if substrateFun:
             return substrateFun(self._createComponent(asn1Spec, tagSet),
                                 substrate, length)
+
         head, tail = substrate[:length], substrate[length:]
@@ -694,3 +823,4 @@
         head, tail = substrate[:length], substrate[length:]
+
         return self._createComponent(asn1Spec, tagSet, value=head), tail
 
@@ -695,8 +825,10 @@
         return self._createComponent(asn1Spec, tagSet, value=head), tail
 
-    def indefLenValueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet,
-                             length, state, decodeFun, substrateFun):
+    def indefLenValueDecoder(self, substrate, asn1Spec,
+                             tagSet=None, length=None, state=None,
+                             decodeFun=None, substrateFun=None,
+                             **options):
         if asn1Spec is not None and tagSet == asn1Spec.tagSet:
             # tagged Any type -- consume header substrate
             header = null
         else:
@@ -699,7 +831,9 @@
         if asn1Spec is not None and tagSet == asn1Spec.tagSet:
             # tagged Any type -- consume header substrate
             header = null
         else:
+            fullSubstrate = options['fullSubstrate']
+
             # untagged Any, recover header substrate
             header = fullSubstrate[:-len(substrate)]
 
@@ -716,7 +850,7 @@
         while substrate:
             component, substrate = decodeFun(substrate, asn1Spec,
                                              substrateFun=substrateFun,
-                                             allowEoo=True)
+                                             allowEoo=True, **options)
             if component is eoo.endOfOctets:
                 break
             header += component
@@ -863,9 +997,11 @@
         self.__tagSetCache = {}
         self.__eooSentinel = ints2octs((0, 0))
 
-    def __call__(self, substrate, asn1Spec=None, tagSet=None,
-                 length=None, state=stDecodeTag, recursiveFlag=True,
-                 substrateFun=None, allowEoo=False):
+    def __call__(self, substrate, asn1Spec=None,
+                 tagSet=None, length=None, state=stDecodeTag,
+                 decodeFun=None, substrateFun=None,
+                 **options):
+
         if debug.logger & debug.flagDecoder:
             logger = debug.logger
         else:
@@ -874,6 +1010,8 @@
         if logger:
             logger('decoder called at scope %s with state %d, working with up to %d octets of substrate: %s' % (debug.scope, state, len(substrate), debug.hexdump(substrate)))
 
+        allowEoo = options.pop('allowEoo', False)
+
         # Look for end-of-octets sentinel
         if allowEoo and self.supportIndefLength:
             if substrate[:2] == self.__eooSentinel:
@@ -1074,9 +1212,10 @@
                     logger('codec %s chosen by ASN.1 spec, decoding %s' % (state is stDecodeValue and concreteDecoder.__class__.__name__ or "<none>", state is stDecodeValue and 'value' or 'as explicit tag'))
                     debug.scope.push(chosenSpec is None and '?' or chosenSpec.__class__.__name__)
             if state is stDecodeValue:
-                if not recursiveFlag and not substrateFun:  # deprecate this
-                    def substrateFun(a, b, c):
-                        return a, b[:c]
+                if not options.get('recursiveFlag', True) and not substrateFun:  # deprecate this
+                    substrateFun = lambda a, b, c: (a, b[:c])
+
+                options.update(fullSubstrate=fullSubstrate)
 
                 if length == -1:  # indef length
                     value, substrate = concreteDecoder.indefLenValueDecoder(
@@ -1080,8 +1219,10 @@
 
                 if length == -1:  # indef length
                     value, substrate = concreteDecoder.indefLenValueDecoder(
-                        fullSubstrate, substrate, asn1Spec, tagSet, length,
-                        stGetValueDecoder, self, substrateFun
+                        substrate, asn1Spec,
+                        tagSet, length, stGetValueDecoder,
+                        self, substrateFun,
+                        **options
                     )
                 else:
                     value, substrate = concreteDecoder.valueDecoder(
@@ -1085,6 +1226,8 @@
                     )
                 else:
                     value, substrate = concreteDecoder.valueDecoder(
-                        fullSubstrate, substrate, asn1Spec, tagSet, length,
-                        stGetValueDecoder, self, substrateFun
+                        substrate, asn1Spec,
+                        tagSet, length, stGetValueDecoder,
+                        self, substrateFun,
+                        **options
                     )
@@ -1090,2 +1233,3 @@
                     )
+
                 if logger:
@@ -1091,5 +1235,6 @@
                 if logger:
-                    logger('codec %s yields type %s, value:\n%s\n...remaining substrate is: %s' % (concreteDecoder.__class__.__name__, value.__class__.__name__, value.prettyPrint(), substrate and debug.hexdump(substrate) or '<none>'))
+                    logger('codec %s yields type %s, value:\n%s\n...remaining substrate is: %s' % (concreteDecoder.__class__.__name__, value.__class__.__name__, isinstance(value, base.Asn1Item) and value.prettyPrint() or value, substrate and debug.hexdump(substrate) or '<none>'))
+
                 state = stStop
                 break
             if state is stTryAsExplicitTag:
diff --git a/pyasn1/codec/ber/encoder.py b/pyasn1/codec/ber/encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL2Jlci9lbmNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL2Jlci9lbmNvZGVyLnB5 100644
--- a/pyasn1/codec/ber/encoder.py
+++ b/pyasn1/codec/ber/encoder.py
@@ -4,7 +4,7 @@
 # Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
 # License: http://pyasn1.sf.net/license.html
 #
-from pyasn1.type import base, tag, univ, char, useful
+from pyasn1.type import tag, univ, char, useful
 from pyasn1.codec.ber import eoo
 from pyasn1.compat.octets import int2oct, oct2int, ints2octs, null, str2octs
 from pyasn1.compat.integer import to_bytes
@@ -23,5 +23,5 @@
         if isConstructed:
             encodedTag |= tag.tagFormatConstructed
         if tagId < 31:
-            return (encodedTag | tagId,)
+            return encodedTag | tagId,
         else:
@@ -27,5 +27,5 @@
         else:
-            substrate = (tagId & 0x7f,)
+            substrate = tagId & 0x7f,
             tagId >>= 7
             while tagId:
                 substrate = (0x80 | (tagId & 0x7f),) + substrate
@@ -36,7 +36,7 @@
         if not defMode and self.supportIndefLenMode:
             return (0x80,)
         if length < 0x80:
-            return (length,)
+            return length,
         else:
             substrate = ()
             while length:
@@ -47,6 +47,6 @@
                 raise error.PyAsn1Error('Length octets overflow (%d)' % substrateLen)
             return (0x80 | substrateLen,) + substrate
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         raise error.PyAsn1Error('Not implemented')
 
@@ -51,18 +51,6 @@
         raise error.PyAsn1Error('Not implemented')
 
-    def _encodeEndOfOctets(self, encodeFun, defMode):
-        if defMode or not self.supportIndefLenMode:
-            return null
-        else:
-            return encodeFun(eoo.endOfOctets, defMode)
-
-    def encode(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        substrate, isConstructed, isOctets = self.encodeValue(
-            encodeFun, value, defMode, maxChunkSize, ifNotEmpty=ifNotEmpty
-        )
-
-        if ifNotEmpty and not substrate:
-            return substrate
+    def encode(self, value, encodeFun, **options):
 
         tagSet = value.tagSet
 
@@ -66,15 +54,37 @@
 
         tagSet = value.tagSet
 
-        # tagged value?
-        if tagSet:
-            if not isConstructed:  # primitive form implies definite mode
-                defMode = True
-            header = self.encodeTag(tagSet[-1], isConstructed)
-            header += self.encodeLength(len(substrate), defMode)
+        # untagged item?
+        if not tagSet:
+            substrate, isConstructed, isOctets = self.encodeValue(
+                value, encodeFun, **options
+            )
+            return substrate
+
+        defMode = options.get('defMode', True)
+
+        for idx, singleTag in enumerate(tagSet.superTags):
+
+            defModeOverride = defMode
+
+            # base tag?
+            if not idx:
+                substrate, isConstructed, isOctets = self.encodeValue(
+                    value, encodeFun, **options
+                )
+
+                if options.get('ifNotEmpty', False) and not substrate:
+                    return substrate
+
+                # primitive form implies definite mode
+                if not isConstructed:
+                    defModeOverride = True
+
+            header = self.encodeTag(singleTag, isConstructed)
+            header += self.encodeLength(len(substrate), defModeOverride)
 
             if isOctets:
                 substrate = ints2octs(header) + substrate
             else:
                 substrate = ints2octs(header + substrate)
 
@@ -75,14 +85,13 @@
 
             if isOctets:
                 substrate = ints2octs(header) + substrate
             else:
                 substrate = ints2octs(header + substrate)
 
-            eoo =  self._encodeEndOfOctets(encodeFun, defMode)
-            if eoo:
-                substrate += eoo
+            if not defModeOverride:
+                substrate += encodeFun(eoo.endOfOctets, defMode=defModeOverride)
 
         return substrate
 
 
 class EndOfOctetsEncoder(AbstractItemEncoder):
@@ -84,9 +93,9 @@
 
         return substrate
 
 
 class EndOfOctetsEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         return null, False, True
 
 
@@ -90,18 +99,6 @@
         return null, False, True
 
 
-class ExplicitlyTaggedItemEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        if isinstance(value, base.AbstractConstructedAsn1Item):
-            value = value.clone(tagSet=value.tagSet[:-1], cloneValueFlag=True)
-        else:
-            value = value.clone(tagSet=value.tagSet[:-1])
-        return encodeFun(value, defMode, maxChunkSize, ifNotEmpty=ifNotEmpty), True, True
-
-
-explicitlyTaggedItemEncoder = ExplicitlyTaggedItemEncoder()
-
-
 class BooleanEncoder(AbstractItemEncoder):
     supportIndefLenMode = False
 
@@ -105,7 +102,7 @@
 class BooleanEncoder(AbstractItemEncoder):
     supportIndefLenMode = False
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         return value and (1,) or (0,), False, False
 
 
@@ -113,7 +110,7 @@
     supportIndefLenMode = False
     supportCompactZero = False
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         if value == 0:
             # de-facto way to encode zero
             if self.supportCompactZero:
@@ -125,10 +122,10 @@
 
 
 class BitStringEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         valueLength = len(value)
         if valueLength % 8:
             alignedValue = value << (8 - valueLength % 8)
         else:
             alignedValue = value
 
@@ -129,10 +126,11 @@
         valueLength = len(value)
         if valueLength % 8:
             alignedValue = value << (8 - valueLength % 8)
         else:
             alignedValue = value
 
+        maxChunkSize = options.get('maxChunkSize', 0)
         if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
             substrate = alignedValue.asOctets()
             return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True
 
@@ -135,9 +133,14 @@
         if not maxChunkSize or len(alignedValue) <= maxChunkSize * 8:
             substrate = alignedValue.asOctets()
             return int2oct(len(substrate) * 8 - valueLength) + substrate, False, True
 
+        # strip off explicit tags
+        alignedValue = alignedValue.clone(
+            tagSet=tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
+        )
+
         stop = 0
         substrate = null
         while stop < valueLength:
             start = stop
             stop = min(start + maxChunkSize * 8, valueLength)
@@ -139,11 +142,11 @@
         stop = 0
         substrate = null
         while stop < valueLength:
             start = stop
             stop = min(start + maxChunkSize * 8, valueLength)
-            substrate += encodeFun(alignedValue[start:stop], defMode, maxChunkSize, ifNotEmpty=ifNotEmpty)
+            substrate += encodeFun(alignedValue[start:stop], **options)
 
         return substrate, True, True
 
 
 class OctetStringEncoder(AbstractItemEncoder):
@@ -145,8 +148,9 @@
 
         return substrate, True, True
 
 
 class OctetStringEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
+        maxChunkSize = options.get('maxChunkSize', 0)
         if not maxChunkSize or len(value) <= maxChunkSize:
             return value.asOctets(), False, True
@@ -151,3 +155,4 @@
         if not maxChunkSize or len(value) <= maxChunkSize:
             return value.asOctets(), False, True
+
         else:
@@ -153,4 +158,7 @@
         else:
+            # will strip off explicit tags
+            baseTagSet = tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
+
             pos = 0
             substrate = null
             while True:
@@ -154,6 +162,7 @@
             pos = 0
             substrate = null
             while True:
-                v = value.clone(value[pos:pos + maxChunkSize])
-                if not v:
+                chunk = value.clone(value[pos:pos + maxChunkSize],
+                                    tagSet=baseTagSet)
+                if not chunk:
                     break
@@ -159,5 +168,5 @@
                     break
-                substrate += encodeFun(v, defMode, maxChunkSize, ifNotEmpty=ifNotEmpty)
+                substrate += encodeFun(chunk, **options)
                 pos += maxChunkSize
 
             return substrate, True, True
@@ -166,10 +175,10 @@
 class NullEncoder(AbstractItemEncoder):
     supportIndefLenMode = False
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         return null, False, True
 
 
 class ObjectIdentifierEncoder(AbstractItemEncoder):
     supportIndefLenMode = False
 
@@ -170,10 +179,10 @@
         return null, False, True
 
 
 class ObjectIdentifierEncoder(AbstractItemEncoder):
     supportIndefLenMode = False
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         oid = value.asTuple()
 
         # Build the first pair
@@ -271,7 +280,7 @@
                 encbase = encBase[i]
         return sign, m, encbase, e
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         if value.isPlusInf:
             return (0x40,), False, False
         if value.isMinusInf:
@@ -342,5 +351,5 @@
 
 
 class SequenceEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         value.verifySizeSpec()
@@ -346,3 +355,4 @@
         value.verifySizeSpec()
+
         namedTypes = value.componentType
         substrate = null
@@ -347,6 +357,7 @@
         namedTypes = value.componentType
         substrate = null
+
         idx = len(value)
         while idx > 0:
             idx -= 1
             if namedTypes:
@@ -349,6 +360,9 @@
         idx = len(value)
         while idx > 0:
             idx -= 1
             if namedTypes:
-                if namedTypes[idx].isOptional and not value[idx].isValue:
+                namedType = namedTypes[idx]
+                if namedType.isOptional and not value[idx].isValue:
+                    continue
+                if namedType.isDefaulted and value[idx] == namedType.asn1Object:
                     continue
@@ -354,8 +368,16 @@
                     continue
-                if namedTypes[idx].isDefaulted and value[idx] == namedTypes[idx].asn1Object:
-                    continue
-            substrate = encodeFun(value[idx], defMode, maxChunkSize) + substrate
+
+            chunk = encodeFun(value[idx], **options)
+
+            # wrap open type blob if needed
+            if namedTypes and namedType.openType:
+                asn1Spec = namedType.asn1Object
+                if asn1Spec.tagSet and not asn1Spec.isSameTypeWith(value[idx]):
+                    chunk = encodeFun(asn1Spec.clone(chunk), **options)
+
+            substrate = chunk + substrate
+
         return substrate, True, True
 
 
 class SequenceOfEncoder(AbstractItemEncoder):
@@ -358,10 +380,10 @@
         return substrate, True, True
 
 
 class SequenceOfEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         value.verifySizeSpec()
         substrate = null
         idx = len(value)
         while idx > 0:
             idx -= 1
@@ -363,10 +385,10 @@
         value.verifySizeSpec()
         substrate = null
         idx = len(value)
         while idx > 0:
             idx -= 1
-            substrate = encodeFun(value[idx], defMode, maxChunkSize, ifNotEmpty=False) + substrate
+            substrate = encodeFun(value[idx], **options) + substrate
         return substrate, True, True
 
 
 class ChoiceEncoder(AbstractItemEncoder):
@@ -369,9 +391,9 @@
         return substrate, True, True
 
 
 class ChoiceEncoder(AbstractItemEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return encodeFun(value.getComponent(), defMode, maxChunkSize, ifNotEmpty=False), True, True
+    def encodeValue(self, value, encodeFun, **options):
+        return encodeFun(value.getComponent(), **options), True, True
 
 
 class AnyEncoder(OctetStringEncoder):
@@ -375,8 +397,8 @@
 
 
 class AnyEncoder(OctetStringEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return value.asOctets(), defMode == False, True
+    def encodeValue(self, value, encodeFun, **options):
+        return value.asOctets(), not options.get('defMode', True), True
 
 
 tagMap = {
@@ -448,10 +470,11 @@
 
 
 class Encoder(object):
-    supportIndefLength = True
+    fixedDefLengthMode = None
+    fixedChunkSize = None
 
     # noinspection PyDefaultArgument
     def __init__(self, tagMap, typeMap={}):
         self.__tagMap = tagMap
         self.__typeMap = typeMap
 
@@ -452,13 +475,12 @@
 
     # noinspection PyDefaultArgument
     def __init__(self, tagMap, typeMap={}):
         self.__tagMap = tagMap
         self.__typeMap = typeMap
 
-    def __call__(self, value, defMode=True, maxChunkSize=0, ifNotEmpty=False):
-        if not defMode and not self.supportIndefLength:
-            raise error.PyAsn1Error('Indefinite length encoding not supported by this codec')
+    def __call__(self, value, **options):
+
         if debug.logger & debug.flagEncoder:
             logger = debug.logger
         else:
             logger = None
@@ -461,5 +483,6 @@
         if debug.logger & debug.flagEncoder:
             logger = debug.logger
         else:
             logger = None
+
         if logger:
@@ -465,3 +488,10 @@
         if logger:
-            logger('encoder called in %sdef mode, chunk size %s for type %s, value:\n%s' % (not defMode and 'in' or '', maxChunkSize, value.prettyPrintType(), value.prettyPrint()))
+            logger('encoder called in %sdef mode, chunk size %s for type %s, value:\n%s' % (not options.get('defMode', True) and 'in' or '', options.get('maxChunkSize', 0), value.prettyPrintType(), value.prettyPrint()))
+
+        if self.fixedDefLengthMode is not None:
+            options.update(defMode=self.fixedDefLengthMode)
+
+        if self.fixedChunkSize is not None:
+            options.update(maxChunkSize=self.fixedChunkSize)
+
         tagSet = value.tagSet
@@ -467,5 +497,10 @@
         tagSet = value.tagSet
-        if len(tagSet) > 1:
-            concreteEncoder = explicitlyTaggedItemEncoder
-        else:
+
+        try:
+            concreteEncoder = self.__typeMap[value.typeId]
+
+        except KeyError:
+            # use base type for codec lookup to recover untagged types
+            baseTagSet = tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
+
             try:
@@ -471,3 +506,4 @@
             try:
-                concreteEncoder = self.__typeMap[value.typeId]
+                concreteEncoder = self.__tagMap[baseTagSet]
+
             except KeyError:
@@ -473,15 +509,11 @@
             except KeyError:
-                # use base type for codec lookup to recover untagged types
-                baseTagSet = tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
-                try:
-                    concreteEncoder = self.__tagMap[baseTagSet]
-                except KeyError:
-                    raise error.PyAsn1Error('No encoder for %s' % (value,))
-            if logger:
-                logger('using value codec %s chosen by %s' % (concreteEncoder.__class__.__name__, tagSet))
-        substrate = concreteEncoder.encode(
-            self, value, defMode, maxChunkSize, ifNotEmpty=ifNotEmpty
-        )
+                raise error.PyAsn1Error('No encoder for %s' % (value,))
+
+        if logger:
+            logger('using value codec %s chosen by %s' % (concreteEncoder.__class__.__name__, tagSet))
+
+        substrate = concreteEncoder.encode(value, self, **options)
+
         if logger:
             logger('codec %s built %s octets of substrate: %s\nencoder completed' % (concreteEncoder, len(substrate), debug.hexdump(substrate)))
         return substrate
diff --git a/pyasn1/codec/cer/decoder.py b/pyasn1/codec/cer/decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL2Nlci9kZWNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL2Nlci9kZWNvZGVyLnB5 100644
--- a/pyasn1/codec/cer/decoder.py
+++ b/pyasn1/codec/cer/decoder.py
@@ -15,8 +15,10 @@
 class BooleanDecoder(decoder.AbstractSimpleDecoder):
     protoComponent = univ.Boolean(0)
 
-    def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
-                     state, decodeFun, substrateFun):
+    def valueDecoder(self, substrate, asn1Spec,
+                     tagSet=None, length=None, state=None,
+                     decodeFun=None, substrateFun=None,
+                     **options):
         head, tail = substrate[:length], substrate[length:]
         if not head or length != 1:
             raise error.PyAsn1Error('Not single-octet Boolean payload')
diff --git a/pyasn1/codec/cer/encoder.py b/pyasn1/codec/cer/encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL2Nlci9lbmNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL2Nlci9lbmNvZGVyLnB5 100644
--- a/pyasn1/codec/cer/encoder.py
+++ b/pyasn1/codec/cer/encoder.py
@@ -14,7 +14,7 @@
 
 
 class BooleanEncoder(encoder.IntegerEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         if value == 0:
             substrate = (0,)
         else:
@@ -22,20 +22,6 @@
         return substrate, False, False
 
 
-class BitStringEncoder(encoder.BitStringEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return encoder.BitStringEncoder.encodeValue(
-            self, encodeFun, value, defMode, 1000, ifNotEmpty=ifNotEmpty
-        )
-
-
-class OctetStringEncoder(encoder.OctetStringEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return encoder.OctetStringEncoder.encodeValue(
-            self, encodeFun, value, defMode, 1000, ifNotEmpty=ifNotEmpty
-        )
-
-
 class RealEncoder(encoder.RealEncoder):
     def _chooseEncBase(self, value):
         m, b, e = value
@@ -52,7 +38,7 @@
     minLength = 12
     maxLength = 19
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         # Encoding constraints:
         # - minutes are mandatory, seconds are optional
         # - subseconds must NOT be zero
@@ -74,4 +60,6 @@
         if self.commachar in octets:
             raise error.PyAsn1Error('Comma in fractions disallowed: %r' % value)
 
+        options.update(maxChunkSize=1000)
+
         return encoder.OctetStringEncoder.encodeValue(
@@ -77,5 +65,5 @@
         return encoder.OctetStringEncoder.encodeValue(
-            self, encodeFun, value, defMode, 1000, ifNotEmpty=ifNotEmpty
+            self, value, encodeFun, **options
         )
 
 
@@ -79,7 +67,7 @@
         )
 
 
-class GeneralizedTimeEncoder(TimeEncoderMixIn, OctetStringEncoder):
+class GeneralizedTimeEncoder(TimeEncoderMixIn, encoder.OctetStringEncoder):
     minLength = 12
     maxLength = 19
 
@@ -95,7 +83,7 @@
         # sort by tags regardless of the Choice value (static sort)
         return sorted(components, key=lambda x: isinstance(x, univ.Choice) and x.minTagSet or x.tagSet)
 
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         value.verifySizeSpec()
         substrate = null
         idx = len(value)
@@ -115,5 +103,6 @@
                 compsMap[id(value[idx])] = namedTypes and namedTypes[idx].isOptional
 
             for comp in self._sortComponents(comps):
-                substrate += encodeFun(comp, defMode, maxChunkSize, ifNotEmpty=compsMap[id(comp)])
+                options.update(ifNotEmpty=compsMap[id(comp)])
+                substrate += encodeFun(comp, **options)
         else:
@@ -119,5 +108,5 @@
         else:
-            components = [encodeFun(x, defMode, maxChunkSize) for x in value]
+            components = [encodeFun(x, **options) for x in value]
 
             # sort by serialized and padded components
             if len(components) > 1:
@@ -136,5 +125,5 @@
 
 
 class SequenceEncoder(encoder.SequenceEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         value.verifySizeSpec()
@@ -140,3 +129,4 @@
         value.verifySizeSpec()
+
         namedTypes = value.componentType
         substrate = null
@@ -141,6 +131,7 @@
         namedTypes = value.componentType
         substrate = null
+
         idx = len(value)
         while idx > 0:
             idx -= 1
             if namedTypes:
@@ -143,6 +134,7 @@
         idx = len(value)
         while idx > 0:
             idx -= 1
             if namedTypes:
-                if namedTypes[idx].isOptional and not value[idx].isValue:
+                namedType = namedTypes[idx]
+                if namedType.isOptional and not value[idx].isValue:
                     continue
@@ -148,4 +140,4 @@
                     continue
-                if namedTypes[idx].isDefaulted and value[idx] == namedTypes[idx].asn1Object:
+                if namedType.isDefaulted and value[idx] == namedType.asn1Object:
                     continue
 
@@ -150,9 +142,18 @@
                     continue
 
-            substrate = encodeFun(value[idx], defMode, maxChunkSize,
-                                  namedTypes and namedTypes[idx].isOptional) + substrate
+            options.update(ifNotEmpty=namedTypes and namedType.isOptional)
+
+            chunk = encodeFun(value[idx], **options)
+
+            # wrap open type blob if needed
+            if namedTypes and namedType.openType:
+                asn1Spec = namedType.asn1Object
+                if asn1Spec.tagSet and not asn1Spec.isSameTypeWith(value[idx]):
+                    chunk = encodeFun(asn1Spec.clone(chunk), **options)
+
+            substrate = chunk + substrate
 
         return substrate, True, True
 
 
 class SequenceOfEncoder(encoder.SequenceOfEncoder):
@@ -154,9 +155,9 @@
 
         return substrate, True, True
 
 
 class SequenceOfEncoder(encoder.SequenceOfEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
+    def encodeValue(self, value, encodeFun, **options):
         substrate = null
         idx = len(value)
 
@@ -160,9 +161,9 @@
         substrate = null
         idx = len(value)
 
-        if ifNotEmpty and not idx:
+        if options.get('ifNotEmpty', False) and not idx:
             return substrate, True, True
 
         value.verifySizeSpec()
         while idx > 0:
             idx -= 1
@@ -164,12 +165,12 @@
             return substrate, True, True
 
         value.verifySizeSpec()
         while idx > 0:
             idx -= 1
-            substrate = encodeFun(value[idx], defMode, maxChunkSize, ifNotEmpty=False) + substrate
+            substrate = encodeFun(value[idx], **options) + substrate
         return substrate, True, True
 
 
 tagMap = encoder.tagMap.copy()
 tagMap.update({
     univ.Boolean.tagSet: BooleanEncoder(),
@@ -170,11 +171,9 @@
         return substrate, True, True
 
 
 tagMap = encoder.tagMap.copy()
 tagMap.update({
     univ.Boolean.tagSet: BooleanEncoder(),
-    univ.BitString.tagSet: BitStringEncoder(),
-    univ.OctetString.tagSet: OctetStringEncoder(),
     univ.Real.tagSet: RealEncoder(),
     useful.GeneralizedTime.tagSet: GeneralizedTimeEncoder(),
     useful.UTCTime.tagSet: UTCTimeEncoder(),
@@ -186,8 +185,6 @@
 typeMap = encoder.typeMap.copy()
 typeMap.update({
     univ.Boolean.typeId: BooleanEncoder(),
-    univ.BitString.typeId: BitStringEncoder(),
-    univ.OctetString.typeId: OctetStringEncoder(),
     univ.Real.typeId: RealEncoder(),
     useful.GeneralizedTime.typeId: GeneralizedTimeEncoder(),
     useful.UTCTime.typeId: UTCTimeEncoder(),
@@ -200,9 +197,8 @@
 
 
 class Encoder(encoder.Encoder):
-
-    def __call__(self, value, defMode=False, maxChunkSize=0, ifNotEmpty=False):
-        return encoder.Encoder.__call__(self, value, defMode, maxChunkSize, ifNotEmpty)
+    fixedDefLengthMode = False
+    fixedChunkSize = 1000
 
 #: Turns ASN.1 object into CER octet stream.
 #:
diff --git a/pyasn1/codec/der/encoder.py b/pyasn1/codec/der/encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL2Rlci9lbmNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL2Rlci9lbmNvZGVyLnB5 100644
--- a/pyasn1/codec/der/encoder.py
+++ b/pyasn1/codec/der/encoder.py
@@ -6,8 +6,7 @@
 #
 from pyasn1.type import univ
 from pyasn1.codec.cer import encoder
-from pyasn1 import error
 
 __all__ = ['encode']
 
 
@@ -10,19 +9,7 @@
 
 __all__ = ['encode']
 
 
-class BitStringEncoder(encoder.BitStringEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return encoder.BitStringEncoder.encodeValue(
-            self, encodeFun, value, defMode, 0, ifNotEmpty=ifNotEmpty
-        )
-
-class OctetStringEncoder(encoder.OctetStringEncoder):
-    def encodeValue(self, encodeFun, value, defMode, maxChunkSize, ifNotEmpty=False):
-        return encoder.OctetStringEncoder.encodeValue(
-            self, encodeFun, value, defMode, 0, ifNotEmpty=ifNotEmpty
-        )
-
 class SetOfEncoder(encoder.SetOfEncoder):
     @staticmethod
     def _sortComponents(components):
@@ -31,11 +18,9 @@
 
 tagMap = encoder.tagMap.copy()
 tagMap.update({
-    univ.BitString.tagSet: BitStringEncoder(),
-    univ.OctetString.tagSet: OctetStringEncoder(),
     # Set & SetOf have same tags
     univ.SetOf.tagSet: SetOfEncoder()
 })
 
 typeMap = encoder.typeMap.copy()
 typeMap.update({
@@ -36,11 +21,9 @@
     # Set & SetOf have same tags
     univ.SetOf.tagSet: SetOfEncoder()
 })
 
 typeMap = encoder.typeMap.copy()
 typeMap.update({
-    univ.BitString.typeId: BitStringEncoder(),
-    univ.OctetString.typeId: OctetStringEncoder(),
     # Set & SetOf have same tags
     univ.Set.typeId: SetOfEncoder(),
     univ.SetOf.typeId: SetOfEncoder()
@@ -48,12 +31,8 @@
 
 
 class Encoder(encoder.Encoder):
-    supportIndefLength = False
-
-    def __call__(self, value, defMode=True, maxChunkSize=0, ifNotEmpty=False):
-        if not defMode:
-            raise error.PyAsn1Error('DER forbids indefinite length mode')
-        return encoder.Encoder.__call__(self, value, defMode, maxChunkSize, ifNotEmpty=ifNotEmpty)
+    fixedDefLengthMode = True
+    fixedChunkSize = 0
 
 #: Turns ASN.1 object into DER octet stream.
 #:
diff --git a/pyasn1/codec/native/decoder.py b/pyasn1/codec/native/decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL25hdGl2ZS9kZWNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL25hdGl2ZS9kZWNvZGVyLnB5 100644
--- a/pyasn1/codec/native/decoder.py
+++ b/pyasn1/codec/native/decoder.py
@@ -11,8 +11,8 @@
 
 
 class AbstractScalarDecoder(object):
-    def __call__(self, pyObject, asn1Spec, decoderFunc=None):
+    def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
         return asn1Spec.clone(pyObject)
 
 
 class BitStringDecoder(AbstractScalarDecoder):
@@ -15,9 +15,9 @@
         return asn1Spec.clone(pyObject)
 
 
 class BitStringDecoder(AbstractScalarDecoder):
-    def __call__(self, pyObject, asn1Spec, decoderFunc=None):
+    def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
         return asn1Spec.clone(univ.BitString.fromBinaryString(pyObject))
 
 
 class SequenceOrSetDecoder(object):
@@ -20,11 +20,11 @@
         return asn1Spec.clone(univ.BitString.fromBinaryString(pyObject))
 
 
 class SequenceOrSetDecoder(object):
-    def __call__(self, pyObject, asn1Spec, decoderFunc):
+    def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
         asn1Value = asn1Spec.clone()
 
         componentsTypes = asn1Spec.componentType
 
         for field in asn1Value:
             if field in pyObject:
@@ -25,12 +25,12 @@
         asn1Value = asn1Spec.clone()
 
         componentsTypes = asn1Spec.componentType
 
         for field in asn1Value:
             if field in pyObject:
-                asn1Value[field] = decoderFunc(pyObject[field], componentsTypes[field].asn1Object)
+                asn1Value[field] = decodeFun(pyObject[field], componentsTypes[field].asn1Object, **options)
 
         return asn1Value
 
 
 class SequenceOfOrSetOfDecoder(object):
@@ -32,9 +32,9 @@
 
         return asn1Value
 
 
 class SequenceOfOrSetOfDecoder(object):
-    def __call__(self, pyObject, asn1Spec, decoderFunc):
+    def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
         asn1Value = asn1Spec.clone()
 
         for pyValue in pyObject:
@@ -38,9 +38,9 @@
         asn1Value = asn1Spec.clone()
 
         for pyValue in pyObject:
-            asn1Value.append(decoderFunc(pyValue, asn1Spec.componentType.asn1Object))
+            asn1Value.append(decodeFun(pyValue, asn1Spec.componentType), **options)
 
         return asn1Value
 
 
 class ChoiceDecoder(object):
@@ -42,12 +42,12 @@
 
         return asn1Value
 
 
 class ChoiceDecoder(object):
-    def __call__(self, pyObject, asn1Spec, decoderFunc):
+    def __call__(self, pyObject, asn1Spec, decodeFun=None, **options):
         asn1Value = asn1Spec.clone()
 
         componentsTypes = asn1Spec.componentType
 
         for field in pyObject:
             if field in componentsTypes:
@@ -48,10 +48,10 @@
         asn1Value = asn1Spec.clone()
 
         componentsTypes = asn1Spec.componentType
 
         for field in pyObject:
             if field in componentsTypes:
-                asn1Value[field] = decoderFunc(pyObject[field], componentsTypes[field].asn1Object)
+                asn1Value[field] = decodeFun(pyObject[field], componentsTypes[field].asn1Object, **options)
                 break
 
         return asn1Value
@@ -130,7 +130,7 @@
         self.__tagMap = tagMap
         self.__typeMap = typeMap
 
-    def __call__(self, pyObject, asn1Spec):
+    def __call__(self, pyObject, asn1Spec, **options):
         if debug.logger & debug.flagDecoder:
             logger = debug.logger
         else:
@@ -144,6 +144,7 @@
 
         try:
             valueDecoder = self.__typeMap[asn1Spec.typeId]
+
         except KeyError:
             # use base type for codec lookup to recover untagged types
             baseTagSet = tag.TagSet(asn1Spec.tagSet.baseTag, asn1Spec.tagSet.baseTag)
@@ -147,6 +148,7 @@
         except KeyError:
             # use base type for codec lookup to recover untagged types
             baseTagSet = tag.TagSet(asn1Spec.tagSet.baseTag, asn1Spec.tagSet.baseTag)
+
             try:
                 valueDecoder = self.__tagMap[baseTagSet]
             except KeyError:
@@ -155,7 +157,7 @@
         if logger:
             logger('calling decoder %s on Python type %s <%s>' % (type(valueDecoder).__name__, type(pyObject).__name__, repr(pyObject)))
 
-        value = valueDecoder(pyObject, asn1Spec, self)
+        value = valueDecoder(pyObject, asn1Spec, self, **options)
 
         if logger:
             logger('decoder %s produced ASN.1 type %s <%s>' % (type(valueDecoder).__name__, type(value).__name__, repr(value)))
diff --git a/pyasn1/codec/native/encoder.py b/pyasn1/codec/native/encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvZGVjL25hdGl2ZS9lbmNvZGVyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvZGVjL25hdGl2ZS9lbmNvZGVyLnB5 100644
--- a/pyasn1/codec/native/encoder.py
+++ b/pyasn1/codec/native/encoder.py
@@ -10,10 +10,10 @@
 except ImportError:
     OrderedDict = dict
 
-from pyasn1.type import base, univ, char, useful
+from pyasn1.type import base, univ, tag, char, useful
 from pyasn1 import debug, error
 
 __all__ = ['encode']
 
 
 class AbstractItemEncoder(object):
@@ -14,10 +14,10 @@
 from pyasn1 import debug, error
 
 __all__ = ['encode']
 
 
 class AbstractItemEncoder(object):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         raise error.PyAsn1Error('Not implemented')
 
 
@@ -21,16 +21,4 @@
         raise error.PyAsn1Error('Not implemented')
 
 
-class ExplicitlyTaggedItemEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
-        if isinstance(value, base.AbstractConstructedAsn1Item):
-            value = value.clone(tagSet=value.tagSet[:-1],
-                                cloneValueFlag=1)
-        else:
-            value = value.clone(tagSet=value.tagSet[:-1])
-        return encodeFun(value)
-
-explicitlyTaggedItemEncoder = ExplicitlyTaggedItemEncoder()
-
-
 class BooleanEncoder(AbstractItemEncoder):
@@ -36,6 +24,6 @@
 class BooleanEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return bool(value)
 
 
 class IntegerEncoder(AbstractItemEncoder):
@@ -38,9 +26,9 @@
         return bool(value)
 
 
 class IntegerEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return int(value)
 
 
 class BitStringEncoder(AbstractItemEncoder):
@@ -43,9 +31,9 @@
         return int(value)
 
 
 class BitStringEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return str(value)
 
 
 class OctetStringEncoder(AbstractItemEncoder):
@@ -48,9 +36,9 @@
         return str(value)
 
 
 class OctetStringEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return value.asOctets()
 
 
 class TextStringEncoder(AbstractItemEncoder):
@@ -53,9 +41,9 @@
         return value.asOctets()
 
 
 class TextStringEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return value.prettyPrint()
 
 
 class NullEncoder(AbstractItemEncoder):
@@ -58,9 +46,9 @@
         return value.prettyPrint()
 
 
 class NullEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return None
 
 
 class ObjectIdentifierEncoder(AbstractItemEncoder):
@@ -63,9 +51,9 @@
         return None
 
 
 class ObjectIdentifierEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return str(value)
 
 
 class RealEncoder(AbstractItemEncoder):
@@ -68,10 +56,10 @@
         return str(value)
 
 
 class RealEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return float(value)
 
 
 class SetEncoder(AbstractItemEncoder):
     protoDict = dict
@@ -73,7 +61,8 @@
         return float(value)
 
 
 class SetEncoder(AbstractItemEncoder):
     protoDict = dict
-    def encode(self, encodeFun, value):
+
+    def encode(self, value, encodeFun, **options):
         value.verifySizeSpec()
@@ -79,3 +68,4 @@
         value.verifySizeSpec()
+
         namedTypes = value.componentType
         substrate = self.protoDict()
@@ -80,5 +70,6 @@
         namedTypes = value.componentType
         substrate = self.protoDict()
+
         for idx, (key, subValue) in enumerate(value.items()):
             if namedTypes and namedTypes[idx].isOptional and not value[idx].isValue:
                 continue
@@ -82,7 +73,7 @@
         for idx, (key, subValue) in enumerate(value.items()):
             if namedTypes and namedTypes[idx].isOptional and not value[idx].isValue:
                 continue
-            substrate[key] = encodeFun(subValue)
+            substrate[key] = encodeFun(subValue, **options)
         return substrate
 
 
@@ -91,5 +82,5 @@
 
 
 class SequenceOfEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         value.verifySizeSpec()
@@ -95,5 +86,5 @@
         value.verifySizeSpec()
-        return [encodeFun(x) for x in value]
+        return [encodeFun(x, **options) for x in value]
 
 
 class ChoiceEncoder(SequenceEncoder):
@@ -101,7 +92,7 @@
 
 
 class AnyEncoder(AbstractItemEncoder):
-    def encode(self, encodeFun, value):
+    def encode(self, value, encodeFun, **options):
         return value.asOctets()
 
 
@@ -154,11 +145,11 @@
         self.__tagMap = tagMap
         self.__typeMap = typeMap
 
-    def __call__(self, asn1Value):
-        if not isinstance(asn1Value, base.Asn1Item):
+    def __call__(self, value, **options):
+        if not isinstance(value, base.Asn1Item):
             raise error.PyAsn1Error('value is not valid (should be an instance of an ASN.1 Item)')
 
         if debug.logger & debug.flagEncoder:
             logger = debug.logger
         else:
             logger = None
@@ -159,26 +150,8 @@
             raise error.PyAsn1Error('value is not valid (should be an instance of an ASN.1 Item)')
 
         if debug.logger & debug.flagEncoder:
             logger = debug.logger
         else:
             logger = None
-        if logger:
-            debug.scope.push(type(asn1Value).__name__)
-            logger('encoder called for type %s <%s>' % (type(asn1Value).__name__, asn1Value.prettyPrint()))
-
-        tagSet = asn1Value.tagSet
-        if len(tagSet) > 1:
-            concreteEncoder = explicitlyTaggedItemEncoder
-        else:
-            if asn1Value.typeId is not None and asn1Value.typeId in self.__typeMap:
-                concreteEncoder = self.__typeMap[asn1Value.typeId]
-            elif tagSet in self.__tagMap:
-                concreteEncoder = self.__tagMap[tagSet]
-            else:
-                tagSet = asn1Value.baseTagSet
-                if tagSet in self.__tagMap:
-                    concreteEncoder = self.__tagMap[tagSet]
-                else:
-                    raise error.PyAsn1Error('No encoder for %s' % (asn1Value,))
 
         if logger:
@@ -183,4 +156,10 @@
 
         if logger:
-            logger('using value codec %s chosen by %s' % (type(concreteEncoder).__name__, tagSet))
+            debug.scope.push(type(value).__name__)
+            logger('encoder called for type %s <%s>' % (type(value).__name__, value.prettyPrint()))
+
+        tagSet = value.tagSet
+
+        try:
+            concreteEncoder = self.__typeMap[value.typeId]
 
@@ -186,5 +165,18 @@
 
-        pyObject = concreteEncoder.encode(self, asn1Value)
+        except KeyError:
+            # use base type for codec lookup to recover untagged types
+            baseTagSet = tag.TagSet(value.tagSet.baseTag, value.tagSet.baseTag)
+
+            try:
+                concreteEncoder = self.__tagMap[baseTagSet]
+
+            except KeyError:
+                raise error.PyAsn1Error('No encoder for %s' % (value,))
+
+        if logger:
+            logger('using value codec %s chosen by %s' % (concreteEncoder.__class__.__name__, tagSet))
+
+        pyObject = concreteEncoder.encode(value, self, **options)
 
         if logger:
             logger('encoder %s produced: %s' % (type(concreteEncoder).__name__, repr(pyObject)))
diff --git a/pyasn1/compat/calling.py b/pyasn1/compat/calling.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvbXBhdC9jYWxsaW5nLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvbXBhdC9jYWxsaW5nLnB5 100644
--- a/pyasn1/compat/calling.py
+++ b/pyasn1/compat/calling.py
@@ -12,7 +12,8 @@
 if (2, 7) < version_info[:2] < (3, 2):
     import collections
 
-    callable = lambda x: isinstance(x, collections.Callable)
+    def callable(x):
+        return isinstance(x, collections.Callable)
 
 else:
 
diff --git a/pyasn1/compat/integer.py b/pyasn1/compat/integer.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvbXBhdC9pbnRlZ2VyLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvbXBhdC9pbnRlZ2VyLnB5 100644
--- a/pyasn1/compat/integer.py
+++ b/pyasn1/compat/integer.py
@@ -106,4 +106,3 @@
 
     def bitLength(number):
         return int(number).bit_length()
-
diff --git a/pyasn1/compat/string.py b/pyasn1/compat/string.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2NvbXBhdC9zdHJpbmcucHk=..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2NvbXBhdC9zdHJpbmcucHk= 100644
--- a/pyasn1/compat/string.py
+++ b/pyasn1/compat/string.py
@@ -23,4 +23,4 @@
 else:
 
     def partition(string, sep):
-        return string.partition(sep)
\ No newline at end of file
+        return string.partition(sep)
diff --git a/pyasn1/debug.py b/pyasn1/debug.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL2RlYnVnLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL2RlYnVnLnB5 100644
--- a/pyasn1/debug.py
+++ b/pyasn1/debug.py
@@ -17,6 +17,7 @@
 flagAll = 0xffff
 
 flagMap = {
+    'none': flagNone,
     'encoder': flagEncoder,
     'decoder': flagDecoder,
     'all': flagAll
@@ -28,4 +29,5 @@
     def __init__(self, logger=None, handler=None, formatter=None):
         if logger is None:
             logger = logging.getLogger('pyasn1')
+
         logger.setLevel(logging.DEBUG)
@@ -31,3 +33,4 @@
         logger.setLevel(logging.DEBUG)
+
         if handler is None:
             handler = logging.StreamHandler()
@@ -32,4 +35,5 @@
         if handler is None:
             handler = logging.StreamHandler()
+
         if formatter is None:
             formatter = logging.Formatter('%(asctime)s %(name)s: %(message)s')
@@ -34,5 +38,6 @@
         if formatter is None:
             formatter = logging.Formatter('%(asctime)s %(name)s: %(message)s')
+
         handler.setFormatter(formatter)
         handler.setLevel(logging.DEBUG)
         logger.addHandler(handler)
@@ -36,9 +41,10 @@
         handler.setFormatter(formatter)
         handler.setLevel(logging.DEBUG)
         logger.addHandler(handler)
+
         self.__logger = logger
 
     def __call__(self, msg):
         self.__logger.debug(msg)
 
     def __str__(self):
@@ -39,11 +45,11 @@
         self.__logger = logger
 
     def __call__(self, msg):
         self.__logger.debug(msg)
 
     def __str__(self):
-        return '<python built-in logging>'
+        return '<python logging>'
 
 
 if hasattr(logging, 'NullHandler'):
     NullHandler = logging.NullHandler
@@ -46,7 +52,8 @@
 
 
 if hasattr(logging, 'NullHandler'):
     NullHandler = logging.NullHandler
+
 else:
     # Python 2.6 and older
     class NullHandler(logging.Handler):
@@ -55,7 +62,7 @@
 
 
 class Debug(object):
-    defaultPrinter = None
+    defaultPrinter = Printer()
 
     def __init__(self, *flags, **options):
         self._flags = flagNone
@@ -59,13 +66,10 @@
 
     def __init__(self, *flags, **options):
         self._flags = flagNone
-        if options.get('printer') is not None:
-            self._printer = options.get('printer')
-        elif self.defaultPrinter is not None:
-            self._printer = self.defaultPrinter
+
         if 'loggerName' in options:
             # route our logs to parent logger
             self._printer = Printer(
                 logger=logging.getLogger(options['loggerName']),
                 handler=NullHandler()
             )
@@ -66,7 +70,11 @@
         if 'loggerName' in options:
             # route our logs to parent logger
             self._printer = Printer(
                 logger=logging.getLogger(options['loggerName']),
                 handler=NullHandler()
             )
+
+        elif 'printer' in options:
+            self._printer = options.get('printer')
+
         else:
@@ -72,6 +80,8 @@
         else:
-            self._printer = Printer()
-        self('running pyasn1 version %s' % __version__)
-        for f in flags:
-            inverse = f and f[0] in ('!', '~')
+            self._printer = self.defaultPrinter
+
+        self._printer('running pyasn1 %s, debug flags %s' % (__version__, ', '.join(flags)))
+
+        for flag in flags:
+            inverse = flag and flag[0] in ('!', '~')
             if inverse:
@@ -77,4 +87,4 @@
             if inverse:
-                f = f[1:]
+                flag = flag[1:]
             try:
                 if inverse:
@@ -79,4 +89,4 @@
             try:
                 if inverse:
-                    self._flags &= ~flagMap[f]
+                    self._flags &= ~flagMap[flag]
                 else:
@@ -82,3 +92,3 @@
                 else:
-                    self._flags |= flagMap[f]
+                    self._flags |= flagMap[flag]
             except KeyError:
@@ -84,3 +94,3 @@
             except KeyError:
-                raise error.PyAsn1Error('bad debug flag %s' % f)
+                raise error.PyAsn1Error('bad debug flag %s' % flag)
 
@@ -86,5 +96,5 @@
 
-            self('debug category \'%s\' %s' % (f, inverse and 'disabled' or 'enabled'))
+            self._printer("debug category '%s' %s" % (flag, inverse and 'disabled' or 'enabled'))
 
     def __str__(self):
         return 'logger %s, flags %x' % (self._printer, self._flags)
@@ -102,5 +112,5 @@
 logger = 0
 
 
-def setLogger(l):
+def setLogger(userLogger):
     global logger
@@ -106,5 +116,9 @@
     global logger
-    logger = l
+
+    if userLogger:
+        logger = userLogger
+    else:
+        logger = 0
 
 
 def hexdump(octets):
diff --git a/pyasn1/type/namedtype.py b/pyasn1/type/namedtype.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL3R5cGUvbmFtZWR0eXBlLnB5..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL3R5cGUvbmFtZWR0eXBlLnB5 100644
--- a/pyasn1/type/namedtype.py
+++ b/pyasn1/type/namedtype.py
@@ -11,6 +11,12 @@
 
 __all__ = ['NamedType', 'OptionalNamedType', 'DefaultedNamedType', 'NamedTypes']
 
+try:
+    any
+
+except AttributeError:
+    any = lambda x: bool(filter(bool, x))
+
 
 class NamedType(object):
     """Create named field object for a constructed ASN.1 type.
@@ -31,7 +37,7 @@
     isOptional = False
     isDefaulted = False
 
-    def __init__(self, name, asn1Object):
+    def __init__(self, name, asn1Object, openType=None):
         self.__name = name
         self.__type = asn1Object
         self.__nameAndType = name, asn1Object
@@ -35,6 +41,7 @@
         self.__name = name
         self.__type = asn1Object
         self.__nameAndType = name, asn1Object
+        self.__openType = openType
 
     def __repr__(self):
         return '%s(%r, %r)' % (self.__class__.__name__, self.__name, self.__type)
@@ -74,6 +81,10 @@
     def asn1Object(self):
         return self.__type
 
+    @property
+    def openType(self):
+        return self.__openType
+
     # Backward compatibility
 
     def getName(self):
@@ -135,8 +146,11 @@
         self.__ambiguousTypes = 'terminal' not in kwargs and self.__computeAmbiguousTypes() or {}
         self.__uniqueTagMap = self.__computeTagMaps(unique=True)
         self.__nonUniqueTagMap = self.__computeTagMaps(unique=False)
-        self.__hasOptionalOrDefault = bool([True for namedType in self.__namedTypes
-                                            if namedType.isDefaulted or namedType.isOptional])
+        self.__hasOptionalOrDefault = any([True for namedType in self.__namedTypes
+                                           if namedType.isDefaulted or namedType.isOptional])
+        self.__hasOpenTypes = any([True for namedType in self.__namedTypes
+                                   if namedType.openType])
+
         self.__requiredComponents = frozenset(
                 [idx for idx, nt in enumerate(self.__namedTypes) if not nt.isOptional and not nt.isDefaulted]
             )
@@ -523,4 +537,8 @@
         return self.__hasOptionalOrDefault
 
     @property
+    def hasOpenTypes(self):
+        return self.__hasOpenTypes
+
+    @property
     def namedTypes(self):
@@ -526,5 +544,5 @@
     def namedTypes(self):
-        return iter(self.__namedTypes)
+        return tuple(self.__namedTypes)
 
     @property
     def requiredComponents(self):
diff --git a/pyasn1/type/opentype.py b/pyasn1/type/opentype.py
new file mode 100644
index 0000000000000000000000000000000000000000..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL3R5cGUvb3BlbnR5cGUucHk=
--- /dev/null
+++ b/pyasn1/type/opentype.py
@@ -0,0 +1,76 @@
+#
+# This file is part of pyasn1 software.
+#
+# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
+# License: http://pyasn1.sf.net/license.html
+#
+
+__all__ = ['OpenType']
+
+
+class OpenType(object):
+    """Create ASN.1 type map indexed by a value
+
+    The *DefinedBy* object models the ASN.1 *DEFINED BY* clause which maps
+    values to ASN.1 types in the context of the ASN.1 SEQUENCE/SET type.
+
+    OpenType objects are duck-type a read-only Python :class:`dict` objects,
+    however the passed `typeMap` is stored by reference.
+
+    Parameters
+    ----------
+    name: :py:class:`str`
+        Field name
+
+    typeMap: :py:class:`dict`:
+        A map of value->ASN.1 type. It's stored by reference and can be
+        mutated later to register new mappings.
+
+    Examples
+    --------
+
+    .. code-block::
+
+        openType = OpenType(
+            'id',
+            {1: Integer(),
+             2: OctetString()}
+        )
+        Sequence(
+            componentType=NamedTypes(
+                NamedType('id', Integer()),
+                NamedType('blob', Any(), openType=openType)
+            )
+        )
+    """
+
+    def __init__(self, name, typeMap=None):
+        self.__name = name
+        if typeMap is None:
+            self.__typeMap = {}
+        else:
+            self.__typeMap = typeMap
+
+    @property
+    def name(self):
+        return self.__name
+
+    # Python dict protocol
+
+    def values(self):
+        return self.__typeMap.values()
+
+    def keys(self):
+        return self.__typeMap.keys()
+
+    def items(self):
+        return self.__typeMap.items()
+
+    def __contains__(self, key):
+        return key in self.__typeMap
+
+    def __getitem__(self, key):
+        return self.__typeMap[key]
+
+    def __iter__(self):
+        return iter(self.__typeMap)
diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_cHlhc24xL3R5cGUvdW5pdi5weQ==..939e5020b70e488704c674e765288ac585812de6_cHlhc24xL3R5cGUvdW5pdi5weQ== 100644
--- a/pyasn1/type/univ.py
+++ b/pyasn1/type/univ.py
@@ -1498,7 +1498,11 @@
         if self.isInf:
             return self.prettyOut(self._value)
         else:
-            return str(float(self))
+            try:
+                return str(float(self))
+
+            except OverflowError:
+                return '<overflow>'
 
     @property
     def isPlusInf(self):
diff --git a/tests/base.py b/tests/base.py
new file mode 100644
index 0000000000000000000000000000000000000000..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvYmFzZS5weQ==
--- /dev/null
+++ b/tests/base.py
@@ -0,0 +1,22 @@
+#
+# This file is part of pyasn1 software.
+#
+# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
+# License: http://pyasn1.sf.net/license.html
+#
+import sys
+try:
+    import unittest2 as unittest
+except ImportError:
+    import unittest
+
+from pyasn1 import debug
+
+
+class BaseTestCase(unittest.TestCase):
+
+    def setUp(self):
+        debug.setLogger(debug.Debug('all', printer=lambda *x: None))
+
+    def tearDown(self):
+        debug.setLogger(None)
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvYmVyL3Rlc3RfZGVjb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvYmVyL3Rlc3RfZGVjb2Rlci5weQ== 100644
--- a/tests/codec/ber/test_decoder.py
+++ b/tests/codec/ber/test_decoder.py
@@ -10,9 +10,11 @@
 except ImportError:
     import unittest
 
-from pyasn1.type import tag, namedtype, univ, char
+from tests.base import BaseTestCase
+
+from pyasn1.type import tag, namedtype, opentype, univ, char
 from pyasn1.codec.ber import decoder, eoo
 from pyasn1.compat.octets import ints2octs, str2octs, null
 from pyasn1.error import PyAsn1Error
 
 
@@ -14,9 +16,9 @@
 from pyasn1.codec.ber import decoder, eoo
 from pyasn1.compat.octets import ints2octs, str2octs, null
 from pyasn1.error import PyAsn1Error
 
 
-class LargeTagDecoderTestCase(unittest.TestCase):
+class LargeTagDecoderTestCase(BaseTestCase):
     def testLargeTag(self):
         assert decoder.decode(ints2octs((127, 141, 245, 182, 253, 47, 3, 2, 1, 1))) == (1, null)
 
@@ -29,8 +31,8 @@
             ints2octs((0x9f, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer)
 
 
-class DecoderCacheTestCase(unittest.TestCase):
+class DecoderCacheTestCase(BaseTestCase):
     def testCache(self):
         assert decoder.decode(ints2octs((0x1f, 2, 1, 0))) == decoder.decode(ints2octs((0x1f, 2, 1, 0)))
 
 
@@ -33,8 +35,8 @@
     def testCache(self):
         assert decoder.decode(ints2octs((0x1f, 2, 1, 0))) == decoder.decode(ints2octs((0x1f, 2, 1, 0)))
 
 
-class IntegerDecoderTestCase(unittest.TestCase):
+class IntegerDecoderTestCase(BaseTestCase):
     def testPosInt(self):
         assert decoder.decode(ints2octs((2, 1, 12))) == (12, null)
 
@@ -82,7 +84,7 @@
             assert 0, 'wrong tagFormat worked out'
 
 
-class BooleanDecoderTestCase(unittest.TestCase):
+class BooleanDecoderTestCase(BaseTestCase):
     def testTrue(self):
         assert decoder.decode(ints2octs((1, 1, 1))) == (1, null)
 
@@ -104,7 +106,7 @@
             assert 0, 'wrong tagFormat worked out'
 
 
-class BitStringDecoderTestCase(unittest.TestCase):
+class BitStringDecoderTestCase(BaseTestCase):
     def testDefMode(self):
         assert decoder.decode(
             ints2octs((3, 3, 1, 169, 138))
@@ -128,9 +130,9 @@
     def testDefModeChunkedSubst(self):
         assert decoder.decode(
             ints2octs((35, 8, 3, 2, 0, 169, 3, 2, 1, 138)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138)), 8)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138)), str2octs(''))
 
     def testIndefModeChunkedSubst(self):
         assert decoder.decode(
             ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)),
@@ -133,9 +135,9 @@
 
     def testIndefModeChunkedSubst(self):
         assert decoder.decode(
             ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), -1)
+            substrateFun=lambda a, b, c: (b, str2octs(''))
+        ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), str2octs(''))
 
     def testTypeChecking(self):
         try:
@@ -146,7 +148,7 @@
             assert 0, 'accepted mis-encoded bit-string constructed out of an integer'
 
 
-class OctetStringDecoderTestCase(unittest.TestCase):
+class OctetStringDecoderTestCase(BaseTestCase):
     def testDefMode(self):
         assert decoder.decode(
             ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120))
@@ -173,11 +175,10 @@
         assert decoder.decode(
             ints2octs(
                 (36, 23, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)),
-              23)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120)), str2octs(''))
 
     def testIndefModeChunkedSubst(self):
         assert decoder.decode(
             ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111,
                        120, 0, 0)),
@@ -179,7 +180,7 @@
 
     def testIndefModeChunkedSubst(self):
         assert decoder.decode(
             ints2octs((36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111,
                        120, 0, 0)),
-            substrateFun=lambda a, b, c: (b, c)
+            substrateFun=lambda a, b, c: (b, str2octs(''))
         ) == (ints2octs(
@@ -185,4 +186,4 @@
         ) == (ints2octs(
-            (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), -1)
+            (4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0)), str2octs(''))
 
 
@@ -187,4 +188,4 @@
 
 
-class ExpTaggedOctetStringDecoderTestCase(unittest.TestCase):
+class ExpTaggedOctetStringDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -190,4 +191,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.o = univ.OctetString(
             'Quick brown fox',
             tagSet=univ.OctetString.tagSet.tagExplicitly(
@@ -233,11 +235,11 @@
     def testDefModeSubst(self):
         assert decoder.decode(
             ints2octs((101, 17, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), 17)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)), str2octs(''))
 
     def testIndefModeSubst(self):
         assert decoder.decode(
             ints2octs((
                       101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0,
                       0, 0, 0)),
@@ -238,8 +240,8 @@
 
     def testIndefModeSubst(self):
         assert decoder.decode(
             ints2octs((
                       101, 128, 36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0,
                       0, 0, 0)),
-            substrateFun=lambda a, b, c: (b, c)
+            substrateFun=lambda a, b, c: (b, str2octs(''))
         ) == (ints2octs(
@@ -245,4 +247,4 @@
         ) == (ints2octs(
-            (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), -1)
+            (36, 128, 4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120, 0, 0, 0, 0)), str2octs(''))
 
 
@@ -247,6 +249,6 @@
 
 
-class NullDecoderTestCase(unittest.TestCase):
+class NullDecoderTestCase(BaseTestCase):
     def testNull(self):
         assert decoder.decode(ints2octs((5, 0))) == (null, null)
 
@@ -261,7 +263,7 @@
 
 # Useful analysis of OID encoding issues could be found here:
 # http://www.viathinksoft.de/~daniel-marschall/asn.1/oid_facts.html
-class ObjectIdentifierDecoderTestCase(unittest.TestCase):
+class ObjectIdentifierDecoderTestCase(BaseTestCase):
     def testOne(self):
         assert decoder.decode(
             ints2octs((6, 6, 43, 6, 0, 191, 255, 126))
@@ -402,7 +404,7 @@
         ) == ((2, 999, 18446744073709551535184467440737095), null)
 
 
-class RealDecoderTestCase(unittest.TestCase):
+class RealDecoderTestCase(BaseTestCase):
     def testChar(self):
         assert decoder.decode(
             ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49))
@@ -478,8 +480,8 @@
 
 
 if sys.version_info[0:2] > (2, 5):
-    class UniversalStringDecoderTestCase(unittest.TestCase):
+    class UniversalStringDecoderTestCase(BaseTestCase):
         def testDecoder(self):
             assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
@@ -482,9 +484,9 @@
         def testDecoder(self):
             assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
-class BMPStringDecoderTestCase(unittest.TestCase):
+class BMPStringDecoderTestCase(BaseTestCase):
     def testDecoder(self):
         assert decoder.decode(ints2octs((30, 6, 0, 97, 0, 98, 0, 99))) == (char.BMPString(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
@@ -487,9 +489,9 @@
     def testDecoder(self):
         assert decoder.decode(ints2octs((30, 6, 0, 97, 0, 98, 0, 99))) == (char.BMPString(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
-class UTF8StringDecoderTestCase(unittest.TestCase):
+class UTF8StringDecoderTestCase(BaseTestCase):
     def testDecoder(self):
         assert decoder.decode(ints2octs((12, 3, 97, 98, 99))) == (char.UTF8String(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
@@ -492,6 +494,6 @@
     def testDecoder(self):
         assert decoder.decode(ints2octs((12, 3, 97, 98, 99))) == (char.UTF8String(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
 
 
-class SequenceOfDecoderTestCase(unittest.TestCase):
+class SequenceOfDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -497,4 +499,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.SequenceOf(componentType=univ.OctetString())
         self.s.setComponentByPosition(0, univ.OctetString('quick brown'))
 
@@ -524,7 +528,7 @@
         ) == (self.s, null)
 
 
-class ExpTaggedSequenceOfDecoderTestCase(unittest.TestCase):
+class ExpTaggedSequenceOfDecoderTestCase(BaseTestCase):
 
     def testWithSchema(self):
         s = univ.SequenceOf().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))
@@ -545,5 +549,5 @@
         assert s.tagSet == s2.tagSet
 
 
-class SequenceOfDecoderWithSchemaTestCase(unittest.TestCase):
+class SequenceOfDecoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -549,4 +553,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SequenceOf(componentType=univ.OctetString())
         self.s.setComponentByPosition(0, univ.OctetString('quick brown'))
 
@@ -571,5 +576,5 @@
         ) == (self.s, null)
 
 
-class SetOfDecoderTestCase(unittest.TestCase):
+class SetOfDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -575,4 +580,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SetOf(componentType=univ.OctetString())
         self.s.setComponentByPosition(0, univ.OctetString('quick brown'))
 
@@ -602,5 +608,5 @@
         ) == (self.s, null)
 
 
-class SetOfDecoderWithSchemaTestCase(unittest.TestCase):
+class SetOfDecoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -606,4 +612,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SetOf(componentType=univ.OctetString())
         self.s.setComponentByPosition(0, univ.OctetString('quick brown'))
 
@@ -628,5 +635,5 @@
         ) == (self.s, null)
 
 
-class SequenceDecoderTestCase(unittest.TestCase):
+class SequenceDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -632,4 +639,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
@@ -665,8 +673,8 @@
     def testWithOptionalAndDefaultedDefModeSubst(self):
         assert decoder.decode(
             ints2octs((48, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), 18)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs(''))
 
     def testWithOptionalAndDefaultedIndefModeSubst(self):
         assert decoder.decode(
@@ -670,7 +678,6 @@
 
     def testWithOptionalAndDefaultedIndefModeSubst(self):
         assert decoder.decode(
-            ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1,
-                       0, 0)),
-            substrateFun=lambda a, b, c: (b, c)
+            ints2octs((48, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)),
+            substrateFun=lambda a, b, c: (b, str2octs(''))
         ) == (ints2octs(
@@ -676,5 +683,5 @@
         ) == (ints2octs(
-            (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), -1)
+            (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs(''))
 
     def testTagFormat(self):
         try:
@@ -687,5 +694,5 @@
             assert 0, 'wrong tagFormat worked out'
 
 
-class SequenceDecoderWithSchemaTestCase(unittest.TestCase):
+class SequenceDecoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -691,4 +698,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
@@ -720,7 +728,7 @@
     def testDefMode(self):
         self.__init()
         assert decoder.decode(
-            ints2octs((48, 128, 5, 0, 0, 0)), asn1Spec=self.s
+            ints2octs((48, 2, 5, 0)), asn1Spec=self.s
         ) == (self.s, null)
 
     def testIndefMode(self):
@@ -823,5 +831,5 @@
         ) == (self.s, null)
 
 
-class SetDecoderTestCase(unittest.TestCase):
+class SequenceDecoderWithIntegerOpenTypesTestCase(BaseTestCase):
     def setUp(self):
@@ -827,4 +835,54 @@
     def setUp(self):
+        openType = opentype.OpenType(
+            'id',
+            {1: univ.Integer(),
+             2: univ.OctetString()}
+        )
+        self.s = univ.Sequence(
+            componentType=namedtype.NamedTypes(
+                namedtype.NamedType('id', univ.Integer()),
+                namedtype.NamedType('blob', univ.Any(), openType=openType)
+            )
+        )
+
+    def testDecodeOpenTypesChoiceOne(self):
+        s, r = decoder.decode(
+            ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s,
+            decodeOpenTypes=True
+        )
+        assert not r
+        assert s[0] == 1
+        assert s[1] == 12
+
+    def testDecodeOpenTypesChoiceTwo(self):
+        s, r = decoder.decode(
+            ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s,
+            decodeOpenTypes = True
+        )
+        assert not r
+        assert s[0] == 2
+        assert s[1] == univ.OctetString('quick brown')
+
+    def testDontDecodeOpenTypesChoiceOne(self):
+        s, r = decoder.decode(
+            ints2octs((48, 6, 2, 1, 1, 2, 1, 12)), asn1Spec=self.s
+        )
+        assert not r
+        assert s[0] == 1
+        assert s[1] == ints2octs((2, 1, 12))
+
+    def testDontDecodeOpenTypesChoiceTwo(self):
+        s, r = decoder.decode(
+            ints2octs((48, 16, 2, 1, 2, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110)), asn1Spec=self.s
+        )
+        assert not r
+        assert s[0] == 2
+        assert s[1] == ints2octs((4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110))
+
+
+class SetDecoderTestCase(BaseTestCase):
+    def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
@@ -860,9 +918,9 @@
     def testWithOptionalAndDefaultedDefModeSubst(self):
         assert decoder.decode(
             ints2octs((49, 18, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)),
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), 18)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1)), str2octs(''))
 
     def testWithOptionalAndDefaultedIndefModeSubst(self):
         assert decoder.decode(
             ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)),
@@ -865,6 +923,6 @@
 
     def testWithOptionalAndDefaultedIndefModeSubst(self):
         assert decoder.decode(
             ints2octs((49, 128, 5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)),
-            substrateFun=lambda a, b, c: (b, c)
+            substrateFun=lambda a, b, c: (b, str2octs(''))
         ) == (ints2octs(
@@ -870,5 +928,5 @@
         ) == (ints2octs(
-            (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), -1)
+            (5, 0, 36, 128, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0)), str2octs(''))
 
     def testTagFormat(self):
         try:
@@ -881,5 +939,5 @@
             assert 0, 'wrong tagFormat worked out'
 
 
-class SetDecoderWithSchemaTestCase(unittest.TestCase):
+class SetDecoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -885,4 +943,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
@@ -1020,5 +1079,5 @@
         ) == (self.s, null)
 
 
-class SequenceOfWithExpTaggedOctetStringDecoder(unittest.TestCase):
+class SequenceOfWithExpTaggedOctetStringDecoder(BaseTestCase):
     def setUp(self):
@@ -1024,4 +1083,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SequenceOf(
             componentType=univ.OctetString().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))
         )
@@ -1065,5 +1125,5 @@
         assert s.tagSet == self.s.tagSet
 
 
-class SequenceWithExpTaggedOctetStringDecoder(unittest.TestCase):
+class SequenceWithExpTaggedOctetStringDecoder(BaseTestCase):
     def setUp(self):
@@ -1069,4 +1129,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType(
@@ -1114,5 +1175,5 @@
         assert s.tagSet == self.s.tagSet
 
 
-class ChoiceDecoderTestCase(unittest.TestCase):
+class ChoiceDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -1118,4 +1179,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Choice(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
@@ -1153,5 +1215,5 @@
         assert decoder.decode(ints2octs((164, 128, 5, 0, 0, 0)), asn1Spec=s) == (s, null)
 
 
-class AnyDecoderTestCase(unittest.TestCase):
+class AnyDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -1157,4 +1219,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Any()
 
     def testByUntagged(self):
@@ -1187,10 +1250,10 @@
         assert decoder.decode(
             ints2octs((4, 3, 102, 111, 120)),
             asn1Spec=self.s,
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((4, 3, 102, 111, 120)), 5)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((4, 3, 102, 111, 120)), str2octs(''))
 
     def testTaggedExSubst(self):
         assert decoder.decode(
             ints2octs((164, 5, 4, 3, 102, 111, 120)),
             asn1Spec=self.s,
@@ -1192,9 +1255,9 @@
 
     def testTaggedExSubst(self):
         assert decoder.decode(
             ints2octs((164, 5, 4, 3, 102, 111, 120)),
             asn1Spec=self.s,
-            substrateFun=lambda a, b, c: (b, c)
-        ) == (ints2octs((164, 5, 4, 3, 102, 111, 120)), 7)
+            substrateFun=lambda a, b, c: (b, b[c:])
+        ) == (ints2octs((164, 5, 4, 3, 102, 111, 120)), str2octs(''))
 
 
@@ -1199,6 +1262,6 @@
 
 
-class EndOfOctetsTestCase(unittest.TestCase):
+class EndOfOctetsTestCase(BaseTestCase):
     def testUnexpectedEoo(self):
         try:
             decoder.decode(ints2octs((0, 0)))
@@ -1249,5 +1312,5 @@
             assert 0, 'end-of-contents octets accepted with unexpected data'
 
 
-class NonStringDecoderTestCase(unittest.TestCase):
+class NonStringDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -1253,4 +1316,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null(null)),
diff --git a/tests/codec/ber/test_encoder.py b/tests/codec/ber/test_encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvYmVyL3Rlc3RfZW5jb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvYmVyL3Rlc3RfZW5jb2Rlci5weQ== 100644
--- a/tests/codec/ber/test_encoder.py
+++ b/tests/codec/ber/test_encoder.py
@@ -5,5 +5,6 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
@@ -8,5 +9,6 @@
 try:
     import unittest2 as unittest
+
 except ImportError:
     import unittest
 
@@ -10,7 +12,9 @@
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import tag, namedtype, univ, char
 from pyasn1.codec.ber import encoder
 from pyasn1.compat.octets import ints2octs
 from pyasn1.error import PyAsn1Error
@@ -13,7 +17,6 @@
 from pyasn1.type import tag, namedtype, univ, char
 from pyasn1.codec.ber import encoder
 from pyasn1.compat.octets import ints2octs
 from pyasn1.error import PyAsn1Error
-from sys import version_info
 
 
@@ -18,4 +21,4 @@
 
 
-class LargeTagEncoderTestCase(unittest.TestCase):
+class LargeTagEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -21,4 +24,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.o = univ.Integer().subtype(
             value=1, explicitTag=tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0xdeadbeaf)
         )
@@ -27,7 +32,7 @@
         assert encoder.encode(self.o) == ints2octs((127, 141, 245, 182, 253, 47, 3, 2, 1, 1))
 
 
-class IntegerEncoderTestCase(unittest.TestCase):
+class IntegerEncoderTestCase(BaseTestCase):
     def testPosInt(self):
         assert encoder.encode(univ.Integer(12)) == ints2octs((2, 1, 12))
 
@@ -57,7 +62,7 @@
         ) == ints2octs((2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1))
 
 
-class BooleanEncoderTestCase(unittest.TestCase):
+class BooleanEncoderTestCase(BaseTestCase):
     def testTrue(self):
         assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 1))
 
@@ -65,5 +70,5 @@
         assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0))
 
 
-class BitStringEncoderTestCase(unittest.TestCase):
+class BitStringEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -69,4 +74,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.b = univ.BitString((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1))
 
     def testDefMode(self):
@@ -91,5 +97,5 @@
         assert encoder.encode(univ.BitString([])) == ints2octs((3, 1, 0))
 
 
-class OctetStringEncoderTestCase(unittest.TestCase):
+class OctetStringEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -95,4 +101,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.o = univ.OctetString('Quick brown fox')
 
     def testDefMode(self):
@@ -117,5 +124,5 @@
                         32, 4, 3, 102,  111, 120, 0, 0))
 
 
-class ExpTaggedOctetStringEncoderTestCase(unittest.TestCase):
+class ExpTaggedOctetStringEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -121,4 +128,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.o = univ.OctetString().subtype(
             value='Quick brown fox',
             explicitTag=tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 5)
@@ -142,7 +150,6 @@
     def testIndefModeChunked(self):
         assert encoder.encode(
             self.o, defMode=False, maxChunkSize=4
-        ) == ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3,
-                        102, 111, 120, 0, 0, 0, 0))
+        ) == ints2octs((101, 128, 36, 128, 4, 4, 81, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 4, 111, 119, 110, 32, 4, 3, 102, 111, 120, 0, 0, 0, 0))
 
 
@@ -147,7 +154,7 @@
 
 
-class NullEncoderTestCase(unittest.TestCase):
+class NullEncoderTestCase(BaseTestCase):
     def testNull(self):
         assert encoder.encode(univ.Null('')) == ints2octs((5, 0))
 
 
@@ -150,8 +157,8 @@
     def testNull(self):
         assert encoder.encode(univ.Null('')) == ints2octs((5, 0))
 
 
-class ObjectIdentifierEncoderTestCase(unittest.TestCase):
+class ObjectIdentifierEncoderTestCase(BaseTestCase):
     def testOne(self):
         assert encoder.encode(
             univ.ObjectIdentifier((1, 3, 6, 0, 0xffffe))
@@ -259,7 +266,7 @@
                         0xB8, 0xCB, 0xE2, 0xB6, 0x47))
 
 
-class RealEncoderTestCase(unittest.TestCase):
+class RealEncoderTestCase(BaseTestCase):
     def testChar(self):
         assert encoder.encode(
             univ.Real((123, 10, 11))
@@ -323,6 +330,6 @@
         assert encoder.encode(univ.Real(0)) == ints2octs((9, 0))
 
 
-if version_info[0:2] > (2, 5):
-    class UniversalStringEncoderTestCase(unittest.TestCase):
+if sys.version_info[0:2] > (2, 5):
+    class UniversalStringEncoderTestCase(BaseTestCase):
         def testEncoding(self):
@@ -328,5 +335,5 @@
         def testEncoding(self):
-            assert encoder.encode(char.UniversalString(version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
+            assert encoder.encode(char.UniversalString(sys.version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
                 (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
 
 
@@ -330,5 +337,5 @@
                 (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
 
 
-class BMPStringEncoderTestCase(unittest.TestCase):
+class BMPStringEncoderTestCase(BaseTestCase):
     def testEncoding(self):
@@ -334,5 +341,5 @@
     def testEncoding(self):
-        assert encoder.encode(char.BMPString(version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
+        assert encoder.encode(char.BMPString(sys.version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
             (30, 6, 0, 97, 0, 98, 0, 99)), 'Incorrect encoding'
 
 
@@ -336,5 +343,5 @@
             (30, 6, 0, 97, 0, 98, 0, 99)), 'Incorrect encoding'
 
 
-class UTF8StringEncoderTestCase(unittest.TestCase):
+class UTF8StringEncoderTestCase(BaseTestCase):
     def testEncoding(self):
@@ -340,5 +347,5 @@
     def testEncoding(self):
-        assert encoder.encode(char.UTF8String(version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
+        assert encoder.encode(char.UTF8String(sys.version_info[0] == 3 and 'abc' or unicode('abc'))) == ints2octs(
             (12, 3, 97, 98, 99)), 'Incorrect encoding'
 
 
@@ -342,7 +349,7 @@
             (12, 3, 97, 98, 99)), 'Incorrect encoding'
 
 
-class SequenceOfEncoderTestCase(unittest.TestCase):
+class SequenceOfEncoderTestCase(BaseTestCase):
     def testEmpty(self):
         s = univ.SequenceOf()
         assert encoder.encode(s) == ints2octs((48, 0))
@@ -374,5 +381,5 @@
         ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0))
 
 
-class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceOfEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -378,4 +385,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SequenceOf(componentType=univ.OctetString())
 
     def __init(self):
@@ -405,7 +413,7 @@
         ) == ints2octs((48, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0))
 
 
-class SetOfEncoderTestCase(unittest.TestCase):
+class SetOfEncoderTestCase(BaseTestCase):
     def testEmpty(self):
         s = univ.SetOf()
         assert encoder.encode(s) == ints2octs((49, 0))
@@ -437,5 +445,5 @@
         ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0))
 
 
-class SetOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SetOfEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -441,4 +449,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SetOf(componentType=univ.OctetString())
 
     def __init(self):
@@ -468,5 +477,5 @@
         ) == ints2octs((49, 128, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 0, 0))
 
 
-class SequenceEncoderTestCase(unittest.TestCase):
+class SequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -472,4 +481,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence()
         self.s.setComponentByPosition(0, univ.Null(''))
         self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -494,5 +504,5 @@
         ) == ints2octs((48, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0))
 
 
-class SequenceEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -498,4 +508,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null()),
@@ -618,5 +629,5 @@
                         0, 2, 1, 1, 0, 0))
 
 
-class SetEncoderTestCase(unittest.TestCase):
+class ExpTaggedSequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -622,4 +633,31 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+        s = univ.Sequence(
+            componentType=namedtype.NamedTypes(
+                namedtype.NamedType('number', univ.Integer()),
+            )
+        )
+
+        s = s.subtype(
+            explicitTag=tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 5)
+        )
+
+        s[0] = 12
+
+        self.s = s
+
+    def testDefMode(self):
+        assert encoder.encode(self.s) == ints2octs((101, 5, 48, 3, 2, 1, 12))
+
+    def testIndefMode(self):
+        assert encoder.encode(
+            self.s, defMode=False
+        ) == ints2octs((101, 128, 48, 128, 2, 1, 12, 0, 0, 0, 0))
+
+
+class SetEncoderTestCase(BaseTestCase):
+    def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set()
         self.s.setComponentByPosition(0, univ.Null(''))
         self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -644,5 +682,5 @@
         ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0))
 
 
-class SetEncoderWithSchemaTestCase(unittest.TestCase):
+class SetEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -648,4 +686,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null()),
@@ -767,7 +806,7 @@
         ) == ints2octs((49, 128, 5, 0, 36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0, 2, 1, 1, 0, 0))
 
 
-class ChoiceEncoderTestCase(unittest.TestCase):
+class ChoiceEncoderTestCase(BaseTestCase):
 
     def testEmpty(self):
         s = univ.Choice()
@@ -810,5 +849,5 @@
         ) == ints2octs((36, 128, 4, 4, 113, 117, 105, 99, 4, 4, 107, 32, 98, 114, 4, 3, 111, 119, 110, 0, 0))
 
 
-class ChoiceEncoderWithSchemaTestCase(unittest.TestCase):
+class ChoiceEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -814,4 +853,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Choice(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null('')),
@@ -853,5 +893,5 @@
             (164, 128, 36, 128, 4, 3, 97, 98, 99, 4, 3, 100, 101, 102, 4, 2, 103, 104, 0, 0, 0, 0))
 
 
-class AnyEncoderTestCase(unittest.TestCase):
+class AnyEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -857,4 +897,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Any(encoder.encode(univ.OctetString('fox')))
 
     def testUntagged(self):
diff --git a/tests/codec/cer/test_decoder.py b/tests/codec/cer/test_decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvY2VyL3Rlc3RfZGVjb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvY2VyL3Rlc3RfZGVjb2Rlci5weQ== 100644
--- a/tests/codec/cer/test_decoder.py
+++ b/tests/codec/cer/test_decoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,10 +9,12 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.codec.cer import decoder
 from pyasn1.compat.octets import ints2octs, str2octs, null
 from pyasn1.error import PyAsn1Error
 
 
@@ -13,9 +16,9 @@
 from pyasn1.codec.cer import decoder
 from pyasn1.compat.octets import ints2octs, str2octs, null
 from pyasn1.error import PyAsn1Error
 
 
-class BooleanDecoderTestCase(unittest.TestCase):
+class BooleanDecoderTestCase(BaseTestCase):
     def testTrue(self):
         assert decoder.decode(ints2octs((1, 1, 255))) == (1, null)
 
@@ -34,7 +37,7 @@
         except PyAsn1Error:
             pass
 
-class BitStringDecoderTestCase(unittest.TestCase):
+class BitStringDecoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert decoder.decode(
             ints2octs((3, 3, 6, 170, 128))
@@ -48,7 +51,7 @@
     # TODO: test failures on short chunked and long unchunked substrate samples
 
 
-class OctetStringDecoderTestCase(unittest.TestCase):
+class OctetStringDecoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert decoder.decode(
             ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120)),
diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvY2VyL3Rlc3RfZW5jb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvY2VyL3Rlc3RfZW5jb2Rlci5weQ== 100644
--- a/tests/codec/cer/test_encoder.py
+++ b/tests/codec/cer/test_encoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,11 +9,13 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import namedtype, univ, useful
 from pyasn1.codec.cer import encoder
 from pyasn1.compat.octets import ints2octs
 from pyasn1.error import PyAsn1Error
 
 
@@ -13,10 +16,10 @@
 from pyasn1.type import namedtype, univ, useful
 from pyasn1.codec.cer import encoder
 from pyasn1.compat.octets import ints2octs
 from pyasn1.error import PyAsn1Error
 
 
-class BooleanEncoderTestCase(unittest.TestCase):
+class BooleanEncoderTestCase(BaseTestCase):
     def testTrue(self):
         assert encoder.encode(univ.Boolean(1)) == ints2octs((1, 1, 255))
 
@@ -24,7 +27,7 @@
         assert encoder.encode(univ.Boolean(0)) == ints2octs((1, 1, 0))
 
 
-class BitStringEncoderTestCase(unittest.TestCase):
+class BitStringEncoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert encoder.encode(
             univ.BitString((1, 0) * 5)
@@ -34,7 +37,7 @@
         assert encoder.encode(univ.BitString((1, 0) * 501)) == ints2octs((3, 127, 6) + (170,) * 125 + (128,))
 
 
-class OctetStringEncoderTestCase(unittest.TestCase):
+class OctetStringEncoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert encoder.encode(
             univ.OctetString('Quick brown fox')
@@ -46,7 +49,7 @@
         ) == ints2octs((36, 128, 4, 130, 3, 232) + (81,) * 1000 + (4, 1, 81, 0, 0))
 
 
-class GeneralizedTimeEncoderTestCase(unittest.TestCase):
+class GeneralizedTimeEncoderTestCase(BaseTestCase):
     #    def testExtraZeroInSeconds(self):
     #        try:
     #            assert encoder.encode(
@@ -104,7 +107,7 @@
              ) == ints2octs((24, 13, 50, 48, 49, 55, 48, 56, 48, 49, 49, 50, 48, 49, 90))
 
 
-class UTCTimeEncoderTestCase(unittest.TestCase):
+class UTCTimeEncoderTestCase(BaseTestCase):
     def testFractionOfSecond(self):
         try:
             assert encoder.encode(
@@ -146,7 +149,7 @@
              ) == ints2octs((23, 11, 57, 57, 48, 56, 48, 49, 49, 50, 48, 49, 90))
 
 
-class SequenceOfEncoderTestCase(unittest.TestCase):
+class SequenceOfEncoderTestCase(BaseTestCase):
     def testEmpty(self):
         s = univ.SequenceOf()
         assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
@@ -176,5 +179,5 @@
         assert encoder.encode(s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0))
 
 
-class SequenceOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceOfEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -180,4 +183,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SequenceOf(componentType=univ.OctetString())
 
     def testEmpty(self):
@@ -209,7 +213,7 @@
         assert encoder.encode(self.s) == ints2octs((48, 128, 4, 1, 97, 4, 1, 98, 0, 0))
 
 
-class SetOfEncoderTestCase(unittest.TestCase):
+class SetOfEncoderTestCase(BaseTestCase):
     def testEmpty(self):
         s = univ.SetOf()
         assert encoder.encode(s) == ints2octs((49, 128, 0, 0))
@@ -239,5 +243,5 @@
         assert encoder.encode(s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
 
 
-class SetOfEncoderWithSchemaTestCase(unittest.TestCase):
+class SetOfEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -243,4 +247,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.SetOf(componentType=univ.OctetString())
 
     def testEmpty(self):
@@ -276,5 +281,5 @@
         assert encoder.encode(self.s) == ints2octs((49, 128, 4, 1, 97, 4, 1, 98, 0, 0))
 
 
-class SetEncoderTestCase(unittest.TestCase):
+class SetEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -280,4 +285,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set()
         self.s.setComponentByPosition(0, univ.Null(''))
         self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -302,5 +308,5 @@
         ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
 
 
-class SetEncoderWithSchemaTestCase(unittest.TestCase):
+class SetEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -306,4 +312,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set(componentType=namedtype.NamedTypes(
             namedtype.NamedType('place-holder', univ.Null('')),
             namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -353,5 +360,5 @@
         ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
 
 
-class SetWithChoiceWithSchemaEncoderTestCase(unittest.TestCase):
+class SetWithChoiceWithSchemaEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -357,4 +364,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         c = univ.Choice(componentType=namedtype.NamedTypes(
             namedtype.NamedType('actual', univ.Boolean(0))
         ))
@@ -370,5 +378,5 @@
         assert encoder.encode(self.s) == ints2octs((49, 128, 1, 1, 255, 5, 0, 0, 0))
 
 
-class SetEncoderTestCase(unittest.TestCase):
+class SetEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -374,4 +382,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Set()
         self.s.setComponentByPosition(0, univ.Null(''))
         self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -396,5 +405,5 @@
         ) == ints2octs((49, 128, 2, 1, 1, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 5, 0, 0, 0))
 
 
-class SequenceEncoderTestCase(unittest.TestCase):
+class SequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -400,4 +409,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence()
         self.s.setComponentByPosition(0, univ.Null(''))
         self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
@@ -422,5 +432,5 @@
         ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
 
 
-class SequenceEncoderWithSchemaTestCase(unittest.TestCase):
+class SequenceEncoderWithSchemaTestCase(BaseTestCase):
     def setUp(self):
@@ -426,4 +436,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null('')),
@@ -475,5 +486,5 @@
         ) == ints2octs((48, 128, 5, 0, 4, 11, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 2, 1, 1, 0, 0))
 
 
-class NestedOptionalSequenceEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -479,4 +490,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         inner = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -564,5 +576,5 @@
         assert encoder.encode(s) == ints2octs((48, 128, 48, 128, 2, 1, 123, 0, 0, 0, 0))
 
 
-class NestedOptionalChoiceEncoderTestCase(unittest.TestCase):
+class NestedOptionalChoiceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -568,4 +580,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         layer3 = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -625,5 +638,5 @@
         assert encoder.encode(s) == ints2octs((48, 128, 0, 0))
 
 
-class NestedOptionalSequenceOfEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -629,4 +642,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         layer2 = univ.SequenceOf(
             componentType=univ.OctetString()
         )
diff --git a/tests/codec/der/test_decoder.py b/tests/codec/der/test_decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvZGVyL3Rlc3RfZGVjb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvZGVyL3Rlc3RfZGVjb2Rlci5weQ== 100644
--- a/tests/codec/der/test_decoder.py
+++ b/tests/codec/der/test_decoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,10 +9,12 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.codec.der import decoder
 from pyasn1.compat.octets import ints2octs, null
 from pyasn1.error import PyAsn1Error
 
 
@@ -13,9 +16,9 @@
 from pyasn1.codec.der import decoder
 from pyasn1.compat.octets import ints2octs, null
 from pyasn1.error import PyAsn1Error
 
 
-class BitStringDecoderTestCase(unittest.TestCase):
+class BitStringDecoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert decoder.decode(
             ints2octs((3, 127, 6) + (170,) * 125 + (128,))
@@ -42,7 +45,7 @@
             assert 0, 'chunked encoding tolerated'
 
 
-class OctetStringDecoderTestCase(unittest.TestCase):
+class OctetStringDecoderTestCase(BaseTestCase):
     def testShortMode(self):
         assert decoder.decode(
             '\004\017Quick brown fox'.encode()
diff --git a/tests/codec/der/test_encoder.py b/tests/codec/der/test_encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvZGVyL3Rlc3RfZW5jb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvZGVyL3Rlc3RfZW5jb2Rlci5weQ== 100644
--- a/tests/codec/der/test_encoder.py
+++ b/tests/codec/der/test_encoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,8 +9,10 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import namedtype, univ
 from pyasn1.codec.der import encoder
 from pyasn1.compat.octets import ints2octs
@@ -13,6 +16,5 @@
 from pyasn1.type import namedtype, univ
 from pyasn1.codec.der import encoder
 from pyasn1.compat.octets import ints2octs
-from pyasn1.error import PyAsn1Error
 
 
@@ -17,8 +19,8 @@
 
 
-class OctetStringEncoderTestCase(unittest.TestCase):
-    def testShortMode(self):
+class OctetStringEncoderTestCase(BaseTestCase):
+    def testDefModeShort(self):
         assert encoder.encode(
             univ.OctetString('Quick brown fox')
         ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120))
 
@@ -21,14 +23,6 @@
         assert encoder.encode(
             univ.OctetString('Quick brown fox')
         ) == ints2octs((4, 15, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120))
 
-    def testIndefMode(self):
-        try:
-            encoder.encode(univ.OctetString('Quick brown'), defMode=False)
-        except PyAsn1Error:
-            pass
-        else:
-            assert 0, 'Indefinite length encoding tolerated'
-
-    def testChunkedMode(self):
+    def testDefModeLong(self):
         assert encoder.encode(
@@ -34,5 +28,5 @@
         assert encoder.encode(
-            univ.OctetString('Quick brown'), maxChunkSize=2
-        ) == ints2octs((4, 11, 81, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110))
+            univ.OctetString('Q' * 10000)
+        ) == ints2octs((4, 130, 39, 16) + (81,) * 10000)
 
 
@@ -37,8 +31,8 @@
 
 
-class BitStringEncoderTestCase(unittest.TestCase):
-    def testShortMode(self):
+class BitStringEncoderTestCase(BaseTestCase):
+    def testDefModeShort(self):
         assert encoder.encode(
             univ.BitString((1,))
         ) == ints2octs((3, 2, 7, 128))
 
@@ -41,5 +35,9 @@
         assert encoder.encode(
             univ.BitString((1,))
         ) == ints2octs((3, 2, 7, 128))
 
+    def testDefModeLong(self):
+        assert encoder.encode(
+            univ.BitString((1,) * 80000)
+        ) == ints2octs((3, 130, 39, 17, 0) + (255,) * 10000)
 
@@ -45,3 +43,4 @@
 
-class SetOfEncoderTestCase(unittest.TestCase):
+
+class SetOfEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -47,4 +46,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.SetOf(componentType=univ.OctetString())
 
     def testDefMode1(self):
@@ -75,5 +76,5 @@
 
         assert encoder.encode(self.s) == ints2octs((49, 6, 4, 1, 97, 4, 1, 98))
 
-class SetWithChoiceEncoderTestCase(unittest.TestCase):
+class SetWithChoiceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -79,5 +80,7 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         c = univ.Choice(componentType=namedtype.NamedTypes(
             namedtype.NamedType('name', univ.OctetString()),
             namedtype.NamedType('amount', univ.Boolean()))
         )
@@ -80,7 +83,8 @@
         c = univ.Choice(componentType=namedtype.NamedTypes(
             namedtype.NamedType('name', univ.OctetString()),
             namedtype.NamedType('amount', univ.Boolean()))
         )
+
         self.s = univ.Set(componentType=namedtype.NamedTypes(
             namedtype.NamedType('value', univ.Integer(5)),
             namedtype.NamedType('status', c))
@@ -97,5 +101,5 @@
         assert encoder.encode(self.s) == ints2octs((49, 6, 1, 1, 255, 2, 1, 5))
 
 
-class NestedOptionalSequenceEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -101,4 +105,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         inner = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -186,5 +192,5 @@
         assert encoder.encode(s) == ints2octs((48, 5, 48, 3, 2, 1, 123))
 
 
-class NestedOptionalChoiceEncoderTestCase(unittest.TestCase):
+class NestedOptionalChoiceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -190,4 +196,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         layer3 = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.OptionalNamedType('first-name', univ.OctetString()),
@@ -247,5 +255,5 @@
         assert encoder.encode(s) == ints2octs((48, 0))
 
 
-class NestedOptionalSequenceOfEncoderTestCase(unittest.TestCase):
+class NestedOptionalSequenceOfEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -251,4 +259,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         layer2 = univ.SequenceOf(
             componentType=univ.OctetString()
         )
diff --git a/tests/codec/native/test_decoder.py b/tests/codec/native/test_decoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvbmF0aXZlL3Rlc3RfZGVjb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvbmF0aXZlL3Rlc3RfZGVjb2Rlci5weQ== 100644
--- a/tests/codec/native/test_decoder.py
+++ b/tests/codec/native/test_decoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,10 +9,12 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
-from pyasn1.type import tag, namedtype, univ, char
+from tests.base import BaseTestCase
+
+from pyasn1.type import namedtype, univ
 from pyasn1.codec.native import decoder
 from pyasn1.error import PyAsn1Error
 
 
@@ -14,8 +17,8 @@
 from pyasn1.codec.native import decoder
 from pyasn1.error import PyAsn1Error
 
 
-class BadAsn1SpecTestCase(unittest.TestCase):
+class BadAsn1SpecTestCase(BaseTestCase):
     def testBadSpec(self):
         try:
             decoder.decode('', asn1Spec='not an Asn1Item')
@@ -25,7 +28,7 @@
             assert 0, 'Invalid asn1Spec accepted'
 
 
-class IntegerDecoderTestCase(unittest.TestCase):
+class IntegerDecoderTestCase(BaseTestCase):
     def testPosInt(self):
         assert decoder.decode(12, asn1Spec=univ.Integer()) == univ.Integer(12)
 
@@ -33,7 +36,7 @@
         assert decoder.decode(-12, asn1Spec=univ.Integer()) == univ.Integer(-12)
 
 
-class BooleanDecoderTestCase(unittest.TestCase):
+class BooleanDecoderTestCase(BaseTestCase):
     def testTrue(self):
         assert decoder.decode(True, asn1Spec=univ.Boolean()) == univ.Boolean(True)
 
@@ -41,8 +44,8 @@
         assert decoder.decode(False, asn1Spec=univ.Boolean()) == univ.Boolean(False)
 
 
-class BitStringDecoderTestCase(unittest.TestCase):
+class BitStringDecoderTestCase(BaseTestCase):
     def testSimple(self):
         assert decoder.decode('11111111', asn1Spec=univ.BitString()) == univ.BitString(hexValue='ff')
 
 
@@ -45,9 +48,9 @@
     def testSimple(self):
         assert decoder.decode('11111111', asn1Spec=univ.BitString()) == univ.BitString(hexValue='ff')
 
 
-class OctetStringDecoderTestCase(unittest.TestCase):
+class OctetStringDecoderTestCase(BaseTestCase):
     def testSimple(self):
         assert decoder.decode('Quick brown fox', asn1Spec=univ.OctetString()) == univ.OctetString('Quick brown fox')
 
 
@@ -50,9 +53,9 @@
     def testSimple(self):
         assert decoder.decode('Quick brown fox', asn1Spec=univ.OctetString()) == univ.OctetString('Quick brown fox')
 
 
-class NullDecoderTestCase(unittest.TestCase):
+class NullDecoderTestCase(BaseTestCase):
     def testNull(self):
         assert decoder.decode(None, asn1Spec=univ.Null()) == univ.Null()
 
 
@@ -55,9 +58,9 @@
     def testNull(self):
         assert decoder.decode(None, asn1Spec=univ.Null()) == univ.Null()
 
 
-class ObjectIdentifierDecoderTestCase(unittest.TestCase):
+class ObjectIdentifierDecoderTestCase(BaseTestCase):
     def testOne(self):
         assert decoder.decode('1.3.6.11', asn1Spec=univ.ObjectIdentifier()) == univ.ObjectIdentifier('1.3.6.11')
 
 
@@ -60,9 +63,9 @@
     def testOne(self):
         assert decoder.decode('1.3.6.11', asn1Spec=univ.ObjectIdentifier()) == univ.ObjectIdentifier('1.3.6.11')
 
 
-class RealDecoderTestCase(unittest.TestCase):
+class RealDecoderTestCase(BaseTestCase):
     def testSimple(self):
         assert decoder.decode(1.33, asn1Spec=univ.Real()) == univ.Real(1.33)
 
 
@@ -65,6 +68,6 @@
     def testSimple(self):
         assert decoder.decode(1.33, asn1Spec=univ.Real()) == univ.Real(1.33)
 
 
-class SequenceDecoderTestCase(unittest.TestCase):
+class SequenceDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -70,4 +73,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null()),
@@ -84,5 +89,5 @@
         assert decoder.decode({'place-holder': None, 'first-name': 'xx', 'age': 33}, asn1Spec=self.s) == s
 
 
-class ChoiceDecoderTestCase(unittest.TestCase):
+class ChoiceDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -88,4 +93,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.Choice(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('place-holder', univ.Null()),
@@ -100,5 +107,5 @@
         assert decoder.decode({'first-name': 'xx'}, asn1Spec=self.s) == s
 
 
-class AnyDecoderTestCase(unittest.TestCase):
+class AnyDecoderTestCase(BaseTestCase):
     def setUp(self):
@@ -104,4 +111,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.Any()
 
     def testSimple(self):
diff --git a/tests/codec/native/test_encoder.py b/tests/codec/native/test_encoder.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29kZWMvbmF0aXZlL3Rlc3RfZW5jb2Rlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29kZWMvbmF0aXZlL3Rlc3RfZW5jb2Rlci5weQ== 100644
--- a/tests/codec/native/test_encoder.py
+++ b/tests/codec/native/test_encoder.py
@@ -5,8 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -8,11 +9,13 @@
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
-from pyasn1.type import tag, namedtype, univ
+from tests.base import BaseTestCase
+
+from pyasn1.type import namedtype, univ
 from pyasn1.codec.native import encoder
 from pyasn1.compat.octets import str2octs
 from pyasn1.error import PyAsn1Error
 
 
@@ -14,9 +17,9 @@
 from pyasn1.codec.native import encoder
 from pyasn1.compat.octets import str2octs
 from pyasn1.error import PyAsn1Error
 
 
-class BadAsn1SpecTestCase(unittest.TestCase):
+class BadAsn1SpecTestCase(BaseTestCase):
     def testBadValueType(self):
         try:
             encoder.encode('not an Asn1Item')
@@ -20,5 +23,6 @@
     def testBadValueType(self):
         try:
             encoder.encode('not an Asn1Item')
+
         except PyAsn1Error:
             pass
@@ -23,6 +27,7 @@
         except PyAsn1Error:
             pass
+
         else:
             assert 0, 'Invalid value type accepted'
 
 
@@ -25,8 +30,8 @@
         else:
             assert 0, 'Invalid value type accepted'
 
 
-class IntegerEncoderTestCase(unittest.TestCase):
+class IntegerEncoderTestCase(BaseTestCase):
     def testPosInt(self):
         assert encoder.encode(univ.Integer(12)) == 12
 
@@ -34,7 +39,7 @@
         assert encoder.encode(univ.Integer(-12)) == -12
 
 
-class BooleanEncoderTestCase(unittest.TestCase):
+class BooleanEncoderTestCase(BaseTestCase):
     def testTrue(self):
         assert encoder.encode(univ.Boolean(1)) is True
 
@@ -42,5 +47,5 @@
         assert encoder.encode(univ.Boolean(0)) is False
 
 
-class BitStringEncoderTestCase(unittest.TestCase):
+class BitStringEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -46,7 +51,8 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.b = univ.BitString((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1))
 
     def testValue(self):
         assert encoder.encode(self.b) == '101010011000101'
 
 
@@ -47,8 +53,8 @@
         self.b = univ.BitString((1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1))
 
     def testValue(self):
         assert encoder.encode(self.b) == '101010011000101'
 
 
-class OctetStringEncoderTestCase(unittest.TestCase):
+class OctetStringEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -54,7 +60,8 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.o = univ.OctetString('Quick brown fox')
 
     def testValue(self):
         assert encoder.encode(self.o) == str2octs('Quick brown fox')
 
 
@@ -55,11 +62,11 @@
         self.o = univ.OctetString('Quick brown fox')
 
     def testValue(self):
         assert encoder.encode(self.o) == str2octs('Quick brown fox')
 
 
-class NullEncoderTestCase(unittest.TestCase):
+class NullEncoderTestCase(BaseTestCase):
     def testNull(self):
         assert encoder.encode(univ.Null('')) is None
 
 
@@ -62,9 +69,9 @@
     def testNull(self):
         assert encoder.encode(univ.Null('')) is None
 
 
-class ObjectIdentifierEncoderTestCase(unittest.TestCase):
+class ObjectIdentifierEncoderTestCase(BaseTestCase):
     def testOne(self):
         assert encoder.encode(univ.ObjectIdentifier((1, 3, 6, 0, 12345))) == '1.3.6.0.12345'
 
 
@@ -67,8 +74,8 @@
     def testOne(self):
         assert encoder.encode(univ.ObjectIdentifier((1, 3, 6, 0, 12345))) == '1.3.6.0.12345'
 
 
-class RealEncoderTestCase(unittest.TestCase):
+class RealEncoderTestCase(BaseTestCase):
     def testChar(self):
         assert encoder.encode(univ.Real((123, 10, 11))) == 1.23e+13
 
@@ -79,5 +86,5 @@
         assert encoder.encode(univ.Real('-inf')) == float('-inf')
 
 
-class SequenceEncoderTestCase(unittest.TestCase):
+class SequenceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -83,4 +90,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.s = univ.Sequence(componentType=namedtype.NamedTypes(
             namedtype.NamedType('place-holder', univ.Null('')),
             namedtype.OptionalNamedType('first-name', univ.OctetString('')),
@@ -95,5 +104,5 @@
         assert encoder.encode(s) == {'place-holder': None, 'first-name': str2octs('abc'), 'age': 123}
 
 
-class ChoiceEncoderTestCase(unittest.TestCase):
+class ChoiceEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -99,9 +108,13 @@
     def setUp(self):
-        self.s = univ.Choice(componentType=namedtype.NamedTypes(
-            namedtype.NamedType('place-holder', univ.Null('')),
-            namedtype.NamedType('number', univ.Integer(0)),
-            namedtype.NamedType('string', univ.OctetString())
-        ))
+        BaseTestCase.setUp(self)
+
+        self.s = univ.Choice(
+            componentType=namedtype.NamedTypes(
+                namedtype.NamedType('place-holder', univ.Null('')),
+                namedtype.NamedType('number', univ.Integer(0)),
+                namedtype.NamedType('string', univ.OctetString())
+           )
+        )
 
     def testEmpty(self):
         try:
@@ -116,5 +129,5 @@
         assert encoder.encode(self.s) == {'place-holder': None}
 
 
-class AnyEncoderTestCase(unittest.TestCase):
+class AnyEncoderTestCase(BaseTestCase):
     def setUp(self):
@@ -120,4 +133,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s = univ.Any(encoder.encode(univ.OctetString('fox')))
 
     def testSimple(self):
diff --git a/tests/compat/test_binary.py b/tests/compat/test_binary.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29tcGF0L3Rlc3RfYmluYXJ5LnB5..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29tcGF0L3Rlc3RfYmluYXJ5LnB5 100644
--- a/tests/compat/test_binary.py
+++ b/tests/compat/test_binary.py
@@ -5,10 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
-from pyasn1.compat import binary
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -9,7 +8,8 @@
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
 
@@ -15,5 +15,8 @@
 
-class BinaryTestCase(unittest.TestCase):
+from pyasn1.compat import binary
+
+
+class BinaryTestCase(BaseTestCase):
 
     def test_bin_zero(self):
         assert '0b0' == binary.bin(0)
diff --git a/tests/compat/test_integer.py b/tests/compat/test_integer.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29tcGF0L3Rlc3RfaW50ZWdlci5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29tcGF0L3Rlc3RfaW50ZWdlci5weQ== 100644
--- a/tests/compat/test_integer.py
+++ b/tests/compat/test_integer.py
@@ -5,10 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
-from pyasn1.compat import integer
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -9,7 +8,8 @@
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
 
@@ -15,5 +15,8 @@
 
-class IntegerTestCase(unittest.TestCase):
+from pyasn1.compat import integer
+
+
+class IntegerTestCase(BaseTestCase):
 
     if sys.version_info[0] > 2:
 
diff --git a/tests/compat/test_octets.py b/tests/compat/test_octets.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvY29tcGF0L3Rlc3Rfb2N0ZXRzLnB5..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvY29tcGF0L3Rlc3Rfb2N0ZXRzLnB5 100644
--- a/tests/compat/test_octets.py
+++ b/tests/compat/test_octets.py
@@ -5,10 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
-from pyasn1.compat import octets
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -9,7 +8,8 @@
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
 
@@ -15,5 +15,8 @@
 
-class OctetsTestCase(unittest.TestCase):
+from pyasn1.compat import octets
+
+
+class OctetsTestCase(BaseTestCase):
 
     if sys.version_info[0] > 2:
 
diff --git a/tests/test_debug.py b/tests/test_debug.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdGVzdF9kZWJ1Zy5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdGVzdF9kZWJ1Zy5weQ== 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -5,5 +5,6 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
@@ -8,5 +9,6 @@
 try:
     import unittest2 as unittest
+
 except ImportError:
     import unittest
 
@@ -10,6 +12,8 @@
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1 import debug
 from pyasn1 import error
 
@@ -13,5 +17,5 @@
 from pyasn1 import debug
 from pyasn1 import error
 
-class DebugCaseBase(unittest.TestCase):
+class DebugCaseBase(BaseTestCase):
     def testKnownFlags(self):
@@ -17,4 +21,5 @@
     def testKnownFlags(self):
+        debug.setLogger(0)
         debug.setLogger(debug.Debug('all', 'encoder', 'decoder'))
         debug.setLogger(0)
 
diff --git a/tests/type/test_char.py b/tests/type/test_char.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X2NoYXIucHk=..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X2NoYXIucHk= 100644
--- a/tests/type/test_char.py
+++ b/tests/type/test_char.py
@@ -5,12 +5,9 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
-from pyasn1.type import char, univ, constraint
-from pyasn1.compat.octets import ints2octs
-from pyasn1.error import PyAsn1Error
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
@@ -11,7 +8,8 @@
 
 try:
     import unittest2 as unittest
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
 
@@ -17,8 +15,13 @@
 
-class AbstractStringTestCase:
+from pyasn1.type import char, univ, constraint
+from pyasn1.compat.octets import ints2octs
+from pyasn1.error import PyAsn1Error
+
+
+class AbstractStringTestCase(object):
 
     initializer = ()
     encoding = 'us-ascii'
     asn1Type = None
 
     def setUp(self):
@@ -19,9 +22,11 @@
 
     initializer = ()
     encoding = 'us-ascii'
     asn1Type = None
 
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.asn1String = self.asn1Type(ints2octs(self.initializer), encoding=self.encoding)
         self.pythonString = ints2octs(self.initializer).decode(self.encoding)
 
@@ -107,10 +112,10 @@
             assert list(reversed(self.asn1String)) == list(reversed(self.pythonString))
 
 
-class VisibleStringTestCase(AbstractStringTestCase, unittest.TestCase):
+class VisibleStringTestCase(AbstractStringTestCase, BaseTestCase):
 
     initializer = (97, 102)
     encoding = 'us-ascii'
     asn1Type = char.VisibleString
 
 
@@ -111,13 +116,13 @@
 
     initializer = (97, 102)
     encoding = 'us-ascii'
     asn1Type = char.VisibleString
 
 
-class GeneralStringTestCase(AbstractStringTestCase, unittest.TestCase):
+class GeneralStringTestCase(AbstractStringTestCase, BaseTestCase):
 
     initializer = (169, 174)
     encoding = 'iso-8859-1'
     asn1Type = char.GeneralString
 
 
@@ -118,13 +123,13 @@
 
     initializer = (169, 174)
     encoding = 'iso-8859-1'
     asn1Type = char.GeneralString
 
 
-class UTF8StringTestCase(AbstractStringTestCase, unittest.TestCase):
+class UTF8StringTestCase(AbstractStringTestCase, BaseTestCase):
 
     initializer = (209, 132, 208, 176)
     encoding = 'utf-8'
     asn1Type = char.UTF8String
 
 
@@ -125,10 +130,10 @@
 
     initializer = (209, 132, 208, 176)
     encoding = 'utf-8'
     asn1Type = char.UTF8String
 
 
-class BMPStringTestCase(AbstractStringTestCase, unittest.TestCase):
+class BMPStringTestCase(AbstractStringTestCase, BaseTestCase):
 
     initializer = (4, 48, 4, 68)
     encoding = 'utf-16-be'
@@ -139,7 +144,7 @@
 
     # Somehow comparison of UTF-32 encoded strings does not work in Py2
 
-    class UniversalStringTestCase(AbstractStringTestCase, unittest.TestCase):
+    class UniversalStringTestCase(AbstractStringTestCase, BaseTestCase):
         initializer = (0, 0, 4, 48, 0, 0, 4, 68)
         encoding = 'utf-32-be'
         asn1Type = char.UniversalString
diff --git a/tests/type/test_constraint.py b/tests/type/test_constraint.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X2NvbnN0cmFpbnQucHk=..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X2NvbnN0cmFpbnQucHk= 100644
--- a/tests/type/test_constraint.py
+++ b/tests/type/test_constraint.py
@@ -5,9 +5,10 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
@@ -8,9 +9,11 @@
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import constraint, error
 
 
@@ -14,5 +17,5 @@
 from pyasn1.type import constraint, error
 
 
-class SingleValueConstraintTestCase(unittest.TestCase):
+class SingleValueConstraintTestCase(BaseTestCase):
     def setUp(self):
@@ -18,4 +21,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.SingleValueConstraint(1, 2)
         self.c2 = constraint.SingleValueConstraint(3, 4)
 
@@ -28,6 +32,7 @@
     def testGoodVal(self):
         try:
             self.c1(1)
+
         except error.ValueConstraintError:
             assert 0, 'constraint check fails'
 
@@ -40,5 +45,5 @@
             assert 0, 'constraint check fails'
 
 
-class ContainedSubtypeConstraintTestCase(unittest.TestCase):
+class ContainedSubtypeConstraintTestCase(BaseTestCase):
     def setUp(self):
@@ -44,4 +49,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ContainedSubtypeConstraint(
             constraint.SingleValueConstraint(12)
         )
@@ -61,5 +67,5 @@
             assert 0, 'constraint check fails'
 
 
-class ValueRangeConstraintTestCase(unittest.TestCase):
+class ValueRangeConstraintTestCase(BaseTestCase):
     def setUp(self):
@@ -65,4 +71,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ValueRangeConstraint(1, 4)
 
     def testGoodVal(self):
@@ -80,5 +87,5 @@
             assert 0, 'constraint check fails'
 
 
-class ValueSizeConstraintTestCase(unittest.TestCase):
+class ValueSizeConstraintTestCase(BaseTestCase):
     def setUp(self):
@@ -84,4 +91,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ValueSizeConstraint(1, 2)
 
     def testGoodVal(self):
@@ -119,5 +127,5 @@
             assert 0, 'constraint check fails'
 
 
-class ConstraintsIntersectionTestCase(unittest.TestCase):
+class ConstraintsIntersectionTestCase(BaseTestCase):
     def setUp(self):
@@ -123,4 +131,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ConstraintsIntersection(
             constraint.SingleValueConstraint(4),
             constraint.ValueRangeConstraint(2, 4)
@@ -161,7 +170,7 @@
             assert 0, 'constraint check fails'
 
 
-class InnerTypeConstraintTestCase(unittest.TestCase):
+class InnerTypeConstraintTestCase(BaseTestCase):
     def testConst1(self):
         c = constraint.InnerTypeConstraint(
             constraint.SingleValueConstraint(4)
@@ -203,5 +212,5 @@
         # Constraints compositions
 
 
-class ConstraintsIntersectionRangeTestCase(unittest.TestCase):
+class ConstraintsIntersectionRangeTestCase(BaseTestCase):
     def setUp(self):
@@ -207,4 +216,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ConstraintsIntersection(
             constraint.ValueRangeConstraint(1, 9),
             constraint.ValueRangeConstraint(2, 5)
@@ -225,5 +235,5 @@
             assert 0, 'constraint check fails'
 
 
-class ConstraintsUnionTestCase(unittest.TestCase):
+class ConstraintsUnionTestCase(BaseTestCase):
     def setUp(self):
@@ -229,4 +239,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ConstraintsUnion(
             constraint.SingleValueConstraint(5),
             constraint.ValueRangeConstraint(1, 3)
@@ -248,5 +259,5 @@
             assert 0, 'constraint check fails'
 
 
-class ConstraintsExclusionTestCase(unittest.TestCase):
+class ConstraintsExclusionTestCase(BaseTestCase):
     def setUp(self):
@@ -252,4 +263,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.c1 = constraint.ConstraintsExclusion(
             constraint.ValueRangeConstraint(2, 4)
         )
@@ -271,5 +283,5 @@
 
 # Constraints derivations
 
-class DirectDerivationTestCase(unittest.TestCase):
+class DirectDerivationTestCase(BaseTestCase):
     def setUp(self):
@@ -275,2 +287,4 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.c1 = constraint.SingleValueConstraint(5)
@@ -276,4 +290,5 @@
         self.c1 = constraint.SingleValueConstraint(5)
+
         self.c2 = constraint.ConstraintsUnion(
             self.c1, constraint.ValueRangeConstraint(1, 3)
         )
@@ -287,5 +302,5 @@
         assert self.c2.isSubTypeOf(self.c1), 'isSubTypeOf failed'
 
 
-class IndirectDerivationTestCase(unittest.TestCase):
+class IndirectDerivationTestCase(BaseTestCase):
     def setUp(self):
@@ -291,4 +306,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.c1 = constraint.ConstraintsIntersection(
             constraint.ValueRangeConstraint(1, 30)
         )
@@ -292,6 +309,7 @@
         self.c1 = constraint.ConstraintsIntersection(
             constraint.ValueRangeConstraint(1, 30)
         )
+
         self.c2 = constraint.ConstraintsIntersection(
             self.c1, constraint.ValueRangeConstraint(1, 20)
         )
@@ -295,6 +313,7 @@
         self.c2 = constraint.ConstraintsIntersection(
             self.c1, constraint.ValueRangeConstraint(1, 20)
         )
+
         self.c2 = constraint.ConstraintsIntersection(
             self.c2, constraint.ValueRangeConstraint(1, 10)
         )
@@ -307,7 +326,7 @@
         assert not self.c2.isSuperTypeOf(self.c1), 'isSuperTypeOf failed'
         assert self.c2.isSubTypeOf(self.c1), 'isSubTypeOf failed'
 
-# TODO: how to apply size constriants to constructed types?
+# TODO: how to apply size constraints to constructed types?
 
 suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
 
diff --git a/tests/type/test_namedtype.py b/tests/type/test_namedtype.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X25hbWVkdHlwZS5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X25hbWVkdHlwZS5weQ== 100644
--- a/tests/type/test_namedtype.py
+++ b/tests/type/test_namedtype.py
@@ -5,5 +5,6 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
@@ -8,5 +9,6 @@
 try:
     import unittest2 as unittest
+
 except ImportError:
     import unittest
 
@@ -10,7 +12,9 @@
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import namedtype, univ
 from pyasn1.error import PyAsn1Error
 
 
@@ -13,6 +17,6 @@
 from pyasn1.type import namedtype, univ
 from pyasn1.error import PyAsn1Error
 
 
-class NamedTypeCaseBase(unittest.TestCase):
+class NamedTypeCaseBase(BaseTestCase):
     def setUp(self):
@@ -18,4 +22,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.e = namedtype.NamedType('age', univ.Integer(0))
 
     def testIter(self):
@@ -26,5 +31,5 @@
         assert eval(repr(self.e), {'NamedType': namedtype.NamedType, 'Integer': univ.Integer}) == self.e, 'repr() fails'
 
 
-class NamedTypesCaseBase(unittest.TestCase):
+class NamedTypesCaseBase(BaseTestCase):
     def setUp(self):
@@ -30,4 +35,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.e = namedtype.NamedTypes(
             namedtype.NamedType('first-name', univ.OctetString('')),
             namedtype.OptionalNamedType('age', univ.Integer(0)),
@@ -35,9 +42,15 @@
         )
 
     def testRepr(self):
-        assert eval(repr(self.e), {'NamedTypes': namedtype.NamedTypes, 'NamedType': namedtype.NamedType,
-                                   'OptionalNamedType': namedtype.OptionalNamedType, 'Integer': univ.Integer,
-                                   'OctetString': univ.OctetString}) == self.e, 'repr() fails'
+        assert eval(
+            repr(self.e), {
+                'NamedTypes': namedtype.NamedTypes,
+                'NamedType': namedtype.NamedType,
+                'OptionalNamedType': namedtype.OptionalNamedType,
+                'Integer': univ.Integer,
+                'OctetString': univ.OctetString
+            }
+        ) == self.e, 'repr() fails'
 
     def testContains(self):
         assert 'first-name' in self.e
@@ -104,5 +117,5 @@
         assert self.e.getPositionNearType(univ.OctetString.tagSet, 2) == 2
 
 
-class OrderedNamedTypesCaseBase(unittest.TestCase):
+class OrderedNamedTypesCaseBase(BaseTestCase):
     def setUp(self):
@@ -108,4 +121,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.e = namedtype.NamedTypes(
             namedtype.NamedType('first-name', univ.OctetString('')),
             namedtype.NamedType('age', univ.Integer(0))
@@ -116,7 +131,7 @@
             'getTypeByPosition() fails'
 
 
-class DuplicateNamedTypesCaseBase(unittest.TestCase):
+class DuplicateNamedTypesCaseBase(BaseTestCase):
     def testDuplicateDefaultTags(self):
         nt = namedtype.NamedTypes(
             namedtype.NamedType('first-name', univ.Any()),
diff --git a/tests/type/test_namedval.py b/tests/type/test_namedval.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X25hbWVkdmFsLnB5..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X25hbWVkdmFsLnB5 100644
--- a/tests/type/test_namedval.py
+++ b/tests/type/test_namedval.py
@@ -5,9 +5,10 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
@@ -8,9 +9,11 @@
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import namedval
 
 
@@ -14,5 +17,5 @@
 from pyasn1.type import namedval
 
 
-class NamedValuesCaseBase(unittest.TestCase):
+class NamedValuesCaseBase(BaseTestCase):
     def setUp(self):
@@ -18,4 +21,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.e = namedval.NamedValues(('off', 0), ('on', 1))
 
     def testDict(self):
diff --git a/tests/type/test_tag.py b/tests/type/test_tag.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X3RhZy5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X3RhZy5weQ== 100644
--- a/tests/type/test_tag.py
+++ b/tests/type/test_tag.py
@@ -5,9 +5,10 @@
 # License: http://pyasn1.sf.net/license.html
 #
 import sys
+
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
@@ -8,9 +9,11 @@
 try:
     import unittest2 as unittest
 
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
 from pyasn1.type import tag
 
 
@@ -14,5 +17,5 @@
 from pyasn1.type import tag
 
 
-class TagTestCaseBase(unittest.TestCase):
+class TagTestCaseBase(BaseTestCase):
     def setUp(self):
@@ -18,4 +21,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.t1 = tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 3)
         self.t2 = tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 3)
 
@@ -38,5 +42,5 @@
                self.t1[2] == self.t2[2], 'tag sequence protocol fails'
 
 
-class TagSetTestCaseBase(unittest.TestCase):
+class TagSetTestCaseBase(BaseTestCase):
     def setUp(self):
@@ -42,4 +46,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.ts1 = tag.initTagSet(
             tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 12)
         )
@@ -43,6 +49,7 @@
         self.ts1 = tag.initTagSet(
             tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 12)
         )
+
         self.ts2 = tag.initTagSet(
             tag.Tag(tag.tagClassUniversal, tag.tagFormatSimple, 12)
         )
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X3VuaXYucHk=..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X3VuaXYucHk= 100644
--- a/tests/type/test_univ.py
+++ b/tests/type/test_univ.py
@@ -12,6 +12,7 @@
 
 try:
     import unittest2 as unittest
+
 except ImportError:
     import unittest
 
@@ -15,4 +16,5 @@
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
 
@@ -18,5 +20,10 @@
 
-class NoValueTestCase(unittest.TestCase):
+from pyasn1.type import univ, tag, constraint, namedtype, namedval, error
+from pyasn1.compat.octets import str2octs, ints2octs, octs2ints
+from pyasn1.error import PyAsn1Error
+
+
+class NoValueTestCase(BaseTestCase):
     def testSingleton(self):
         assert univ.NoValue() is univ.NoValue(), 'NoValue is not a singleton'
 
@@ -144,7 +151,7 @@
             assert False, 'sizeof failed for NoValue object'
 
 
-class IntegerTestCase(unittest.TestCase):
+class IntegerTestCase(BaseTestCase):
     def testStr(self):
         assert str(univ.Integer(1)) in ('1', '1L'), 'str() fails'
 
@@ -292,7 +299,7 @@
         )
 
 
-class BooleanTestCase(unittest.TestCase):
+class BooleanTestCase(BaseTestCase):
     def testTruth(self):
         assert univ.Boolean(True) and univ.Boolean(1), 'Truth initializer fails'
 
@@ -324,5 +331,5 @@
             assert 0, 'constraint fail'
 
 
-class BitStringTestCase(unittest.TestCase):
+class BitStringTestCase(BaseTestCase):
     def setUp(self):
@@ -328,4 +335,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         self.b = univ.BitString(
             namedValues=namedval.NamedValues(('Active', 0), ('Urgent', 1))
         )
@@ -465,8 +474,8 @@
            assert list(reversed(univ.OctetString(self.encodedPythonString))) == list(reversed(self.encodedPythonString))
 
 
-class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, unittest.TestCase):
+class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, BaseTestCase):
     initializer = (97, 102)
     encoding = 'us-ascii'
 
 
@@ -469,9 +478,9 @@
     initializer = (97, 102)
     encoding = 'us-ascii'
 
 
-class OctetStringWithUtf8TestCase(OctetStringWithUnicodeMixIn, unittest.TestCase):
+class OctetStringWithUtf8TestCase(OctetStringWithUnicodeMixIn, BaseTestCase):
     initializer = (208, 176, 208, 177, 208, 178)
     encoding = 'utf-8'
 
 
@@ -474,8 +483,8 @@
     initializer = (208, 176, 208, 177, 208, 178)
     encoding = 'utf-8'
 
 
-class OctetStringWithUtf16TestCase(OctetStringWithUnicodeMixIn, unittest.TestCase):
+class OctetStringWithUtf16TestCase(OctetStringWithUnicodeMixIn, BaseTestCase):
     initializer = (4, 48, 4, 49, 4, 50)
     encoding = 'utf-16-be'
 
@@ -484,8 +493,8 @@
 
     # Somehow comparison of UTF-32 encoded strings does not work in Py2
 
-    class OctetStringWithUtf32TestCase(OctetStringWithUnicodeMixIn, unittest.TestCase):
+    class OctetStringWithUtf32TestCase(OctetStringWithUnicodeMixIn, BaseTestCase):
         initializer = (0, 0, 4, 48, 0, 0, 4, 49, 0, 0, 4, 50)
         encoding = 'utf-32-be'
 
 
@@ -488,8 +497,8 @@
         initializer = (0, 0, 4, 48, 0, 0, 4, 49, 0, 0, 4, 50)
         encoding = 'utf-32-be'
 
 
-class OctetStringTestCase(unittest.TestCase):
+class OctetStringTestCase(BaseTestCase):
 
     def testBinDefault(self):
 
@@ -539,7 +548,7 @@
         assert OctetString(hexValue="FA9823C43E43510DE3422") == ints2octs((250, 152, 35, 196, 62, 67, 81, 13, 227, 66, 32))
 
 
-class Null(unittest.TestCase):
+class Null(BaseTestCase):
     def testStr(self):
         assert str(univ.Null('')) == '', 'str() fails'
 
@@ -568,7 +577,7 @@
         assert not Null()
 
 
-class RealTestCase(unittest.TestCase):
+class RealTestCase(BaseTestCase):
     def testFloat4BinEnc(self):
         assert univ.Real((0.25, 2, 3)) == 2.0, 'float initializer for binary encoding fails'
 
@@ -701,7 +710,7 @@
         assert Real(1.0) == 1.0
 
 
-class ObjectIdentifier(unittest.TestCase):
+class ObjectIdentifier(BaseTestCase):
     def testStr(self):
         assert str(univ.ObjectIdentifier((1, 3, 6))) == '1.3.6', 'str() fails'
 
@@ -761,5 +770,5 @@
         assert str(ObjectIdentifier((1, 3, 6))) == '1.3.6'
 
 
-class SequenceOf(unittest.TestCase):
+class SequenceOf(BaseTestCase):
     def setUp(self):
@@ -765,4 +774,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s1 = univ.SequenceOf(
             componentType=univ.OctetString('')
         )
@@ -954,5 +964,5 @@
 
         assert n == o
 
-class Sequence(unittest.TestCase):
+class Sequence(BaseTestCase):
     def setUp(self):
@@ -958,4 +968,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s1 = univ.Sequence(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('name', univ.OctetString('')),
@@ -965,11 +976,16 @@
         )
 
     def testRepr(self):
-        assert eval(repr(self.s1.clone().setComponents('a', 'b')),
-                    {'Sequence': univ.Sequence, 'OctetString': univ.OctetString, 'Integer': univ.Integer,
-                     'NamedTypes': namedtype.NamedTypes, 'NamedType': namedtype.NamedType,
-                     'OptionalNamedType': namedtype.OptionalNamedType,
-                     'DefaultedNamedType': namedtype.DefaultedNamedType}) == self.s1.clone().setComponents('a', 'b'), 'repr() fails'
+        assert eval(
+            repr(self.s1.clone().setComponents('a', 'b')),
+            {'Sequence': univ.Sequence,
+             'OctetString': univ.OctetString,
+             'Integer': univ.Integer,
+             'NamedTypes': namedtype.NamedTypes,
+             'NamedType': namedtype.NamedType,
+             'OptionalNamedType': namedtype.OptionalNamedType,
+             'DefaultedNamedType': namedtype.DefaultedNamedType}
+        ) == self.s1.clone().setComponents('a', 'b'), 'repr() fails'
 
     def testTag(self):
         assert self.s1.tagSet == tag.TagSet(
@@ -1140,7 +1156,7 @@
         assert not s[1][1].isValue
 
 
-class SequenceWithoutSchema(unittest.TestCase):
+class SequenceWithoutSchema(BaseTestCase):
 
     def testIter(self):
         s = univ.Sequence()
@@ -1190,5 +1206,5 @@
         assert 'field-0' not in s
 
 
-class SetOf(unittest.TestCase):
+class SetOf(BaseTestCase):
     def setUp(self):
@@ -1194,4 +1210,5 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
         self.s1 = univ.SetOf(componentType=univ.OctetString(''))
 
     def testTag(self):
@@ -1217,5 +1234,5 @@
         assert s == [str2octs('abc')]
 
 
-class Set(unittest.TestCase):
+class Set(BaseTestCase):
     def setUp(self):
@@ -1221,9 +1238,13 @@
     def setUp(self):
-        self.s1 = univ.Set(componentType=namedtype.NamedTypes(
-            namedtype.NamedType('name', univ.OctetString('')),
-            namedtype.OptionalNamedType('null', univ.Null('')),
-            namedtype.DefaultedNamedType('age', univ.Integer(34))
-        ))
+        BaseTestCase.setUp(self)
+
+        self.s1 = univ.Set(
+            componentType=namedtype.NamedTypes(
+                namedtype.NamedType('name', univ.OctetString('')),
+                namedtype.OptionalNamedType('null', univ.Null('')),
+                namedtype.DefaultedNamedType('age', univ.Integer(34))
+            )
+        )
         self.s2 = self.s1.clone()
 
     def testTag(self):
@@ -1280,5 +1301,5 @@
         assert s['name'] == str2octs('abc')
 
 
-class Choice(unittest.TestCase):
+class Choice(BaseTestCase):
     def setUp(self):
@@ -1284,4 +1305,6 @@
     def setUp(self):
+        BaseTestCase.setUp(self)
+
         innerComp = univ.Choice(
             componentType=namedtype.NamedTypes(
                 namedtype.NamedType('count', univ.Integer()),
@@ -1407,4 +1430,4 @@
 suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
 
 if __name__ == '__main__':
-    unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
+    unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/tests/type/test_useful.py b/tests/type/test_useful.py
index 1b5d819813c1a7cc54e121cae5ac41bd7f361720_dGVzdHMvdHlwZS90ZXN0X3VzZWZ1bC5weQ==..939e5020b70e488704c674e765288ac585812de6_dGVzdHMvdHlwZS90ZXN0X3VzZWZ1bC5weQ== 100644
--- a/tests/type/test_useful.py
+++ b/tests/type/test_useful.py
@@ -6,8 +6,6 @@
 #
 import sys
 import datetime
-from pyasn1.type import useful
-from pyasn1.error import PyAsn1Error
 
 try:
     import unittest2 as unittest
@@ -11,6 +9,7 @@
 
 try:
     import unittest2 as unittest
+
 except ImportError:
     import unittest
 
@@ -14,6 +13,9 @@
 except ImportError:
     import unittest
 
+from tests.base import BaseTestCase
+
+from pyasn1.type import useful
 
 class FixedOffset(datetime.tzinfo):
     def __init__(self, offset, name):
@@ -34,7 +36,7 @@
 UTC2 = FixedOffset(120, 'UTC')
 
 
-class ObjectDescriptorTestCase(unittest.TestCase):
+class ObjectDescriptorTestCase(BaseTestCase):
     pass
 
 
@@ -38,7 +40,7 @@
     pass
 
 
-class GeneralizedTimeTestCase(unittest.TestCase):
+class GeneralizedTimeTestCase(BaseTestCase):
 
     def testFromDateTime(self):
         assert useful.GeneralizedTime.fromDateTime(datetime.datetime(2017, 7, 11, 0, 1, 2, 30000, tzinfo=UTC)) == '20170711000102.3Z'
@@ -71,7 +73,7 @@
         assert datetime.datetime(2017, 7, 11, 0) == useful.GeneralizedTime('2017071100').asDateTime
 
 
-class UTCTimeTestCase(unittest.TestCase):
+class UTCTimeTestCase(BaseTestCase):
 
     def testFromDateTime(self):
         assert useful.UTCTime.fromDateTime(datetime.datetime(2017, 7, 11, 0, 1, 2, tzinfo=UTC)) == '170711000102Z'