mirror of
https://github.com/python/cpython.git
synced 2025-07-12 22:05:16 +00:00
bpo-39385: Add an assertNoLogs context manager to unittest.TestCase (GH-18067)
Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
This commit is contained in:
parent
5d5c84ef78
commit
6b34d7b51e
5 changed files with 131 additions and 8 deletions
|
@ -295,7 +295,6 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
|
|||
self._raiseFailure("{} not triggered".format(exc_name))
|
||||
|
||||
|
||||
|
||||
class _OrderedChainMap(collections.ChainMap):
|
||||
def __iter__(self):
|
||||
seen = set()
|
||||
|
@ -788,7 +787,16 @@ class TestCase(object):
|
|||
"""
|
||||
# Lazy import to avoid importing logging if it is not needed.
|
||||
from ._log import _AssertLogsContext
|
||||
return _AssertLogsContext(self, logger, level)
|
||||
return _AssertLogsContext(self, logger, level, no_logs=False)
|
||||
|
||||
def assertNoLogs(self, logger=None, level=None):
|
||||
""" Fail unless no log messages of level *level* or higher are emitted
|
||||
on *logger_name* or its children.
|
||||
|
||||
This method must be used as a context manager.
|
||||
"""
|
||||
from ._log import _AssertLogsContext
|
||||
return _AssertLogsContext(self, logger, level, no_logs=True)
|
||||
|
||||
def _getAssertEqualityFunc(self, first, second):
|
||||
"""Get a detailed comparison function for the types of the two args.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue