Commit dc609c2b authored by Victor Stinner's avatar Victor Stinner

Try to fix test_warnings on Windows

Issue #26567.
parent 976e053c
...@@ -4,7 +4,6 @@ import os ...@@ -4,7 +4,6 @@ import os
from io import StringIO from io import StringIO
import re import re
import sys import sys
import tempfile
import textwrap import textwrap
import unittest import unittest
from test import support from test import support
...@@ -774,8 +773,10 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): ...@@ -774,8 +773,10 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
module = py_warnings module = py_warnings
def test_tracemalloc(self): def test_tracemalloc(self):
with tempfile.NamedTemporaryFile("w", suffix=".py") as tmpfile: self.addCleanup(support.unlink, support.TESTFN)
tmpfile.write(textwrap.dedent("""
with open(support.TESTFN, 'w') as fp:
fp.write(textwrap.dedent("""
def func(): def func():
f = open(__file__) f = open(__file__)
# Emit ResourceWarning # Emit ResourceWarning
...@@ -783,12 +784,12 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): ...@@ -783,12 +784,12 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
func() func()
""")) """))
tmpfile.flush()
fname = tmpfile.name res = assert_python_ok('-Wd', '-X', 'tracemalloc=2', support.TESTFN)
res = assert_python_ok('-Wd', '-X', 'tracemalloc=2', fname)
stderr = res.err.decode('ascii', 'replace') stderr = res.err.decode('ascii', 'replace')
stderr = re.sub('<.*>', '<...>', stderr) stderr = re.sub('<.*>', '<...>', stderr)
expected = textwrap.dedent(f''' expected = textwrap.dedent('''
{fname}:5: ResourceWarning: unclosed file <...> {fname}:5: ResourceWarning: unclosed file <...>
f = None f = None
Object allocated at (most recent call first): Object allocated at (most recent call first):
...@@ -796,7 +797,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): ...@@ -796,7 +797,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
f = open(__file__) f = open(__file__)
File "{fname}", lineno 7 File "{fname}", lineno 7
func() func()
''').strip() ''')
expected = expected.format(fname=support.TESTFN).strip()
self.assertEqual(stderr, expected) self.assertEqual(stderr, expected)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment