Skip to content

Commit 64dfd42

Browse files
author
Alexey Izbyshev
committed
Fix check_no_warnings() docs to reflect what it actually does
My previous understanding of behavior of check_no_resource_warning(), which check_no_warnings() is based on, was incorrect.
1 parent cec8cd7 commit 64dfd42

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
# threads
102102
"threading_setup", "threading_cleanup", "reap_threads", "start_threads",
103103
# miscellaneous
104-
"check_warnings", "check_no_resource_warning", "EnvironmentVarGuard",
104+
"check_warnings", "check_no_resource_warning", "check_no_warnings",
105+
"EnvironmentVarGuard",
105106
"run_with_locale", "swap_item",
106107
"swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
107108
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
@@ -1209,10 +1210,14 @@ def check_warnings(*filters, **kwargs):
12091210

12101211

12111212
@contextlib.contextmanager
1212-
def check_no_warning(testcase, message='', category=Warning, force_gc=False):
1213-
"""Context manager to check that no matching warning is emitted.
1213+
def check_no_warnings(testcase, message='', category=Warning, force_gc=False):
1214+
"""Context manager to check that no warnings are emitted.
12141215
1215-
If force_gc is True, attempt a garbage collection before checking
1216+
This context manager enables a given warning within its scope
1217+
and checks that no warnings are emitted even with that warning
1218+
enabled.
1219+
1220+
If force_gc is True, a garbage collection is attempted before checking
12161221
for warnings. This may help to catch warnings emitted when objects
12171222
are deleted, such as ResourceWarning.
12181223
@@ -1242,7 +1247,7 @@ def check_no_resource_warning(testcase):
12421247
You must remove the object which may emit ResourceWarning before
12431248
the end of the context manager.
12441249
"""
1245-
with check_no_warning(testcase, category=ResourceWarning, force_gc=True):
1250+
with check_no_warnings(testcase, category=ResourceWarning, force_gc=True):
12461251
yield
12471252

12481253

Lib/test/test_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def testSetBufferSize(self):
182182
# make sure that explicitly setting the buffer size doesn't cause
183183
# misbehaviour especially with repeated close() calls
184184
for s in (-1, 0, 512):
185-
with support.check_no_warning(self,
186-
message='line buffering',
187-
category=RuntimeWarning):
185+
with support.check_no_warnings(self,
186+
message='line buffering',
187+
category=RuntimeWarning):
188188
self._checkBufferSize(s)
189189

190190
# test that attempts to use line buffering in binary mode cause

0 commit comments

Comments
 (0)