diff options
author | Kit Choi <kitchoi@users.noreply.github.com> | 2020-07-01 21:08:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 21:08:38 (GMT) |
commit | 6b34d7b51e33fcb21b8827d927474ce9ed1f605c (patch) | |
tree | 3c99cf049311bfa2296d47d69fa998b08da26aab /Lib/unittest/case.py | |
parent | 5d5c84ef78b19211671c2bfa68fe073485135eed (diff) | |
download | cpython-6b34d7b51e33fcb21b8827d927474ce9ed1f605c.zip cpython-6b34d7b51e33fcb21b8827d927474ce9ed1f605c.tar.gz cpython-6b34d7b51e33fcb21b8827d927474ce9ed1f605c.tar.bz2 |
bpo-39385: Add an assertNoLogs context manager to unittest.TestCase (GH-18067)
Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r-- | Lib/unittest/case.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index 52eb7d0..872f121 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -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. |