mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
Correct a failing test when test_import is run after test_coding:
be sure to import a fresh module by removing it from sys.modules
This commit is contained in:
parent
cf171a7fbc
commit
dd9e3b8736
2 changed files with 9 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
import test.test_support, unittest
|
import test.test_support, unittest
|
||||||
|
from test.test_support import TESTFN
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
class CodingTest(unittest.TestCase):
|
class CodingTest(unittest.TestCase):
|
||||||
|
@ -29,8 +30,10 @@ class CodingTest(unittest.TestCase):
|
||||||
def test_file_parse(self):
|
def test_file_parse(self):
|
||||||
# issue1134: all encodings outside latin-1 and utf-8 fail on
|
# issue1134: all encodings outside latin-1 and utf-8 fail on
|
||||||
# multiline strings and long lines (>512 columns)
|
# multiline strings and long lines (>512 columns)
|
||||||
|
if TESTFN in sys.modules:
|
||||||
|
del sys.modules[TESTFN]
|
||||||
sys.path.insert(0, ".")
|
sys.path.insert(0, ".")
|
||||||
filename = test.test_support.TESTFN+".py"
|
filename = TESTFN + ".py"
|
||||||
f = open(filename, "w")
|
f = open(filename, "w")
|
||||||
try:
|
try:
|
||||||
f.write("# -*- coding: cp1252 -*-\n")
|
f.write("# -*- coding: cp1252 -*-\n")
|
||||||
|
@ -39,11 +42,11 @@ class CodingTest(unittest.TestCase):
|
||||||
f.write("'A very long string %s'\n" % ("X" * 1000))
|
f.write("'A very long string %s'\n" % ("X" * 1000))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
__import__(test.test_support.TESTFN)
|
__import__(TESTFN)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
os.remove(test.test_support.TESTFN+".py")
|
os.remove(TESTFN+".py")
|
||||||
os.remove(test.test_support.TESTFN+".pyc")
|
os.remove(TESTFN+".pyc")
|
||||||
sys.path.pop(0)
|
sys.path.pop(0)
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -54,6 +54,8 @@ class ImportTest(unittest.TestCase):
|
||||||
print("b =", b, file=f)
|
print("b =", b, file=f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
if TESTFN in sys.modules:
|
||||||
|
del sys.modules[TESTFN]
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
mod = __import__(TESTFN)
|
mod = __import__(TESTFN)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue