summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-11-13 01:41:00 (GMT)
committerGitHub <noreply@github.com>2018-11-13 01:41:00 (GMT)
commit2c07c493d2eb45101312e3eb3a77f94d0c9cad1f (patch)
tree5cd5016fbf1a2b3833dbeb83ca7c1055c8671c5b /Lib/test/test_warnings
parent1584a0081500d35dc93ff88e5836df35faf3e3e2 (diff)
downloadcpython-2c07c493d2eb45101312e3eb3a77f94d0c9cad1f.zip
cpython-2c07c493d2eb45101312e3eb3a77f94d0c9cad1f.tar.gz
cpython-2c07c493d2eb45101312e3eb3a77f94d0c9cad1f.tar.bz2
bpo-29564: warnings suggests to enable tracemalloc (GH-10486)
The warnings module now suggests to enable tracemalloc if the source is specified, tracemalloc module is available, but tracemalloc is not tracing memory allocations.
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index a4775d0..2c54e61 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -897,12 +897,27 @@ class PyWarningsDisplayTests(WarningsDisplayTests, unittest.TestCase):
func()
"""))
- res = assert_python_ok('-Wd', '-X', 'tracemalloc=2', support.TESTFN)
+ def run(*args):
+ res = assert_python_ok(*args)
+ stderr = res.err.decode('ascii', 'replace')
+ stderr = '\n'.join(stderr.splitlines())
- stderr = res.err.decode('ascii', 'replace')
- # normalize newlines
- stderr = '\n'.join(stderr.splitlines())
- stderr = re.sub('<.*>', '<...>', stderr)
+ # normalize newlines
+ stderr = re.sub('<.*>', '<...>', stderr)
+ return stderr
+
+ # tracemalloc disabled
+ stderr = run('-Wd', support.TESTFN)
+ expected = textwrap.dedent('''
+ {fname}:5: ResourceWarning: unclosed file <...>
+ f = None
+ ResourceWarning: Enable tracemalloc to get the object allocation traceback
+ ''')
+ expected = expected.format(fname=support.TESTFN).strip()
+ self.assertEqual(stderr, expected)
+
+ # tracemalloc enabled
+ stderr = run('-Wd', '-X', 'tracemalloc=2', support.TESTFN)
expected = textwrap.dedent('''
{fname}:5: ResourceWarning: unclosed file <...>
f = None