diff --git a/docs/api.rst b/docs/api.rst index f88eff5e..aa70017f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -27,6 +27,8 @@ Import the :mod:`logot` API in your tests: .. automethod:: assert_not_logged + .. automethod:: clear + .. autoattribute:: DEFAULT_LEVEL .. autoattribute:: DEFAULT_LOGGER diff --git a/logot/_logot.py b/logot/_logot.py index 7db9b292..5af7d525 100644 --- a/logot/_logot.py +++ b/logot/_logot.py @@ -81,6 +81,13 @@ def capturing( logger = validate_logger(logger) return _Capturing(self, _Handler(self, levelno=levelno), logger=logger) + def clear(self) -> None: + """ + Clears any captured logs. + """ + with self._lock: + self._queue.clear() + def assert_logged(self, log: Logged) -> None: """ Fails *immediately* if the expected ``log`` pattern has not arrived. diff --git a/pyproject.toml b/pyproject.toml index 417ff007..1ce8565b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "logot" -version = "0.1.0" +version = "0.1.1" description = "Log-based testing" authors = ["Dave Hall "] license = "MIT" diff --git a/tests/test_logot.py b/tests/test_logot.py index 2814d57f..30060301 100644 --- a/tests/test_logot.py +++ b/tests/test_logot.py @@ -24,6 +24,12 @@ def test_capturing() -> None: logger.setLevel(logging.NOTSET) +def test_clear(logot: Logot) -> None: + logger.info("foo bar") + logot.clear() + logot.assert_not_logged(logged.info("foo bar")) + + def test_assert_logged_pass(logot: Logot) -> None: logger.info("foo bar") logot.assert_logged(logged.info("foo bar"))