-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytest_crayons.py
46 lines (31 loc) · 921 Bytes
/
pytest_crayons.py
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
41
42
43
44
45
46
import pytest
from functools import partial
# Terminal color codes
RED = "\x1b[31m"
GREEN = "\x1b[32m"
YELLOW = "\x1b[33m"
BLUE = "\x1b[34m"
MAGENTA = "\x1b[35m"
CYAN = "\x1b[36m"
RESET = "\x1b[0m"
BOLD = "\x1b[1m"
def _color_print(color: str, func_name: str, text: str):
print(f"{BOLD}{color}{func_name}: {text}{RESET}")
@pytest.fixture()
def red(request):
return partial(_color_print, RED, request.node.name)
@pytest.fixture()
def green(request):
return partial(_color_print, GREEN, request.node.name)
@pytest.fixture()
def yellow(request):
return partial(_color_print, YELLOW, request.node.name)
@pytest.fixture()
def blue(request):
return partial(_color_print, BLUE, request.node.name)
@pytest.fixture()
def magenta(request):
return partial(_color_print, MAGENTA, request.node.name)
@pytest.fixture()
def cyan(request):
return partial(_color_print, CYAN, request.node.name)