diff options
author | Brett Cannon <bcannon@gmail.com> | 2010-07-03 01:32:48 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2010-07-03 01:32:48 (GMT) |
commit | 2cab50b9378731cb64ecb5aa21f72a36e0a7bde3 (patch) | |
tree | db62d91bd0ea89cfdfd5870e044d0de2703f7625 /Lib | |
parent | e401c6842a9e6314c0648d311725b25606966a57 (diff) | |
download | cpython-2cab50b9378731cb64ecb5aa21f72a36e0a7bde3.zip cpython-2cab50b9378731cb64ecb5aa21f72a36e0a7bde3.tar.gz cpython-2cab50b9378731cb64ecb5aa21f72a36e0a7bde3.tar.bz2 |
Make test_import a little bit more robust for cleaning up after itself in the
face of a failure.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_import.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 512759d..929caa6 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -147,22 +147,24 @@ class ImportTests(unittest.TestCase): filename = module + '.py' # Create a file with a list of 65000 elements. - with open(filename, 'w+') as f: + with open(filename, 'w') as f: f.write('d = [\n') for i in range(65000): f.write('"",\n') f.write(']') - # Compile & remove .py file; we only need .pyc (or .pyo). - # Bytecode must be relocated from the PEP 3147 bytecode-only location. - py_compile.compile(filename) - unlink(filename) - make_legacy_pyc(filename) + try: + # Compile & remove .py file; we only need .pyc (or .pyo). + # Bytecode must be relocated from the PEP 3147 bytecode-only location. + py_compile.compile(filename) + finally: + unlink(filename) # Need to be able to load from current dir. sys.path.append('') try: + make_legacy_pyc(filename) # This used to crash. exec('import ' + module) finally: |