#11420: merge with 3.2.
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 65c9f25..72ae145 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -162,8 +162,10 @@
 
             with warnings.catch_warnings():
                 warnings.simplefilter('ignore')
-                mod = imp.load_compiled(
-                    temp_mod_name, imp.cache_from_source(temp_mod_name + '.py'))
+                if not sys.dont_write_bytecode:
+                    mod = imp.load_compiled(
+                        temp_mod_name,
+                        imp.cache_from_source(temp_mod_name + '.py'))
             self.assertEqual(mod.a, 1)
 
             if not os.path.exists(test_package_name):