This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add an assertNoLogs context manager to unittest TestCase
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Kit Yan Choi, ezio.melotti, francois.freitag, mark.dickinson, michael.foord, rbcollins, remi.lapeyre, vinay.sajip, xtreak
Priority: normal Keywords: patch

Created on 2020-01-18 20:25 by Kit Yan Choi, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18067 merged Kit Yan Choi, 2020-01-19 17:21
PR 22317 merged mark.dickinson, 2020-09-19 09:32
Messages (4)
msg360250 - (view) Author: Kit Yan Choi (Kit Yan Choi) * Date: 2020-01-18 20:25
assertLogs is really useful (issue18937). Unfortunately it does not cover the use cases where one wants to ensure no logs are emitted.

Similar to assertLogs, we can have a context manager for asserting no logs, something like this?:

with assertNoLogs(logger, level):
    ...


If logs are unexpected found, the test would fail with the logs captured included in the error message.

Happy to submit a PR if there is interest.
msg367129 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-04-23 16:34
This makes sense, should assertNoWarns() be added too?
msg367134 - (view) Author: Kit Yan Choi (Kit Yan Choi) * Date: 2020-04-23 17:39
Thank you for looking into this.
Yes, I agree it makes sense to have assertNoWarns for the same reason.
msg372794 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-07-01 21:08
New changeset 6b34d7b51e33fcb21b8827d927474ce9ed1f605c by Kit Choi in branch 'master':
bpo-39385: Add an assertNoLogs context manager to unittest.TestCase (GH-18067)
https://github.com/python/cpython/commit/6b34d7b51e33fcb21b8827d927474ce9ed1f605c
History
Date User Action Args
2022-04-11 14:59:25adminsetgithub: 83566
2020-09-19 09:32:42mark.dickinsonsetnosy: + mark.dickinson

pull_requests: + pull_request21362
2020-07-01 21:09:42vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-07-01 21:08:42vinay.sajipsetnosy: + vinay.sajip
messages: + msg372794
2020-06-10 22:02:27remi.lapeyresetversions: + Python 3.10, - Python 3.9
2020-04-23 17:39:13Kit Yan Choisetmessages: + msg367134
2020-04-23 16:34:46remi.lapeyresetnosy: + remi.lapeyre
messages: + msg367129
2020-04-23 16:10:52francois.freitagsetnosy: + francois.freitag
2020-01-19 17:21:16Kit Yan Choisetkeywords: + patch
stage: patch review
pull_requests: + pull_request17459
2020-01-19 15:28:05xtreaksetnosy: + xtreak
2020-01-19 11:19:13SilentGhostsetnosy: + rbcollins, ezio.melotti, michael.foord

versions: + Python 3.9
2020-01-18 20:25:23Kit Yan Choicreate