MCPcopy
hub / github.com/treeverse/dvc / test_nested_exceptions

Method test_nested_exceptions

tests/unit/test_logger.py:150–172  ·  view source on GitHub ↗
(self, caplog, dt)

Source from the content-addressed store, hash-verified

148 assert expected == formatter.format(caplog.records[0])
149
150 def test_nested_exceptions(self, caplog, dt):
151 with caplog.at_level(logging.DEBUG, logger="dvc"):
152 try:
153 raise Exception("first")
154 except Exception as exc: # noqa: BLE001
155 try:
156 raise DvcException("second") from exc
157 except DvcException:
158 stack_trace = traceback.format_exc()
159 logger.exception("message")
160
161 expected = (
162 "{red}{datetime}{nc} "
163 "{red}ERROR{nc}: message - second: first\n"
164 "{stack_trace}".format(
165 stack_trace=stack_trace,
166 **colors,
167 datetime=dt,
168 )
169 )
170 assert expected == formatter.format(caplog.records[0])
171 assert "Exception: first" in stack_trace
172 assert "dvc.exceptions.DvcException: second" in stack_trace
173
174 def test_progress_awareness(self, mocker, capsys, caplog):
175 from dvc.progress import Tqdm

Callers

nothing calls this directly

Calls 2

DvcExceptionClass · 0.90
formatMethod · 0.45

Tested by

no test coverage detected