-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_utils_errors.py
More file actions
40 lines (25 loc) · 1.1 KB
/
test_utils_errors.py
File metadata and controls
40 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import types
import src.venvalid.utils_errors as utils_errors
class DummyConsole:
def __init__(self):
self.last_message = None
def print(self, msg):
self.last_message = msg
def test_pretty_print_error_with_rich(monkeypatch):
dummy_console = DummyConsole()
fake_rich_pkg = types.ModuleType("rich")
fake_rich_pkg.__path__ = [] # mark as package
fake_console_mod = types.ModuleType("rich.console")
setattr(fake_console_mod, "Console", lambda: dummy_console)
monkeypatch.setitem(sys.modules, "rich", fake_rich_pkg)
monkeypatch.setitem(sys.modules, "rich.console", fake_console_mod)
utils_errors.pretty_print_error(ValueError("boom"))
assert dummy_console.last_message is not None
assert "boom" in dummy_console.last_message
def test_pretty_print_error_without_rich(monkeypatch, capsys):
monkeypatch.delitem(sys.modules, "rich.console", raising=False)
monkeypatch.delitem(sys.modules, "rich", raising=False)
utils_errors.pretty_print_error(ValueError("fail"))
out = capsys.readouterr().out
assert "Error: fail" in out