diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-19 01:51:45 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-19 01:51:45 (GMT) |
commit | bfab932971593b6468024e5774653bb2f5047b56 (patch) | |
tree | b171a1178f848e339e4c0a7b982180afb8e9212f /Lib/test/test_warnings | |
parent | f664dc58344fc615f8f5649752bf5cb54efe5b3b (diff) | |
download | cpython-bfab932971593b6468024e5774653bb2f5047b56.zip cpython-bfab932971593b6468024e5774653bb2f5047b56.tar.gz cpython-bfab932971593b6468024e5774653bb2f5047b56.tar.bz2 |
Try to fix test_warnings on Windows
Issue #26567.
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index a1b3dba..be80b05 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -4,7 +4,6 @@ import os from io import StringIO import re import sys -import tempfile import textwrap import unittest from test import support @@ -774,8 +773,10 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): module = py_warnings def test_tracemalloc(self): - with tempfile.NamedTemporaryFile("w", suffix=".py") as tmpfile: - tmpfile.write(textwrap.dedent(""" + self.addCleanup(support.unlink, support.TESTFN) + + with open(support.TESTFN, 'w') as fp: + fp.write(textwrap.dedent(""" def func(): f = open(__file__) # Emit ResourceWarning @@ -783,12 +784,12 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): func() """)) - tmpfile.flush() - fname = tmpfile.name - res = assert_python_ok('-Wd', '-X', 'tracemalloc=2', fname) + + res = assert_python_ok('-Wd', '-X', 'tracemalloc=2', support.TESTFN) + stderr = res.err.decode('ascii', 'replace') stderr = re.sub('<.*>', '<...>', stderr) - expected = textwrap.dedent(f''' + expected = textwrap.dedent(''' {fname}:5: ResourceWarning: unclosed file <...> f = None Object allocated at (most recent call first): @@ -796,7 +797,8 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase): f = open(__file__) File "{fname}", lineno 7 func() - ''').strip() + ''') + expected = expected.format(fname=support.TESTFN).strip() self.assertEqual(stderr, expected) |