bpo-41919, test_codecs: Move codecs.register calls to setUp() (GH-22513)

* Move the codecs' (un)register operation to testcases.
* Remove _codecs._forget_codec() and _PyCodec_Forget()
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 85fac30..fbaea3a 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2529,10 +2529,6 @@
                 streamreader=None, streamwriter=None,
                 incrementaldecoder=cls)
 
-# Register the previous decoder for testing.
-# Disabled by default, tests will enable it.
-codecs.register(StatefulIncrementalDecoder.lookupTestDecoder)
-
 
 class StatefulIncrementalDecoderTest(unittest.TestCase):
     """
@@ -2583,6 +2579,9 @@
         self.testdata = b"AAA\r\nBBB\rCCC\r\nDDD\nEEE\r\n"
         self.normalized = b"AAA\nBBB\nCCC\nDDD\nEEE\n".decode("ascii")
         os_helper.unlink(os_helper.TESTFN)
+        codecs.register(StatefulIncrementalDecoder.lookupTestDecoder)
+        self.addCleanup(codecs.unregister,
+                        StatefulIncrementalDecoder.lookupTestDecoder)
 
     def tearDown(self):
         os_helper.unlink(os_helper.TESTFN)