Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use TESTFN instead of NamedTemporaryFile
  • Loading branch information
ammaraskar committed Jul 12, 2021
commit 012ae63a7863b2c2cc07ce7204d46dab581d50e5
11 changes: 5 additions & 6 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,24 +464,23 @@ def f_with_subscript():
self.assertEqual(result_lines, expected_error.splitlines())

def test_traceback_specialization_with_syntax_error(self):
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as file:
bytecode = compile("1 / 0 / 1 / 2\n", file.name, "exec")
bytecode = compile("1 / 0 / 1 / 2\n", TESTFN, "exec")

# make the file invalid
with open(TESTFN, "w") as file:
# make the file's contents invalid
file.write("1 $ 0 / 1 / 2\n")
file.flush()
self.addCleanup(unlink, TESTFN)

func = partial(exec, bytecode)
result_lines = self.get_exception(func)
os.unlink(file.name)

lineno_f = bytecode.co_firstlineno
expected_error = (
'Traceback (most recent call last):\n'
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
' callable()\n'
' ^^^^^^^^^^\n'
f' File "{file.name}", line {lineno_f}, in <module>\n'
f' File "{TESTFN}", line {lineno_f}, in <module>\n'
" 1 $ 0 / 1 / 2\n"
' ^^^^^\n'
)
Expand Down