Debian Codegraph @

src/pytest_emoji/plugin.py

raw
1 from pytest_emoji import hooks
2
3
4 def pytest_emoji_passed(config):
5 # SMILING FACE WITH OPEN MOUTH
6 return u"😃 ", u"PASSED 😃 "
7
8
9 def pytest_emoji_failed(config):
10 # FACE WITH OPEN MOUTH AND COLD SWEAT
11 return u"😰 ", u"FAILED 😰 "
12
13
14 def pytest_emoji_skipped(config):
15 # FACE WITH ROLLING EYES
16 return u"🙄 ", u"SKIPPED 🙄 "
17
18
19 def pytest_emoji_error(config):
20 # POUTING FACE
21 return u"😡 ", u"ERROR 😡 "
22
23
24 def pytest_emoji_xfailed(config):
25 # DISAPPOINTED FACE
26 return u"😞 ", u"XFAIL 😞 "
27
28
29 def pytest_emoji_xpassed(config):
30 # DIZZY FACE
31 return u"😲 ", u"XPASS 😲 "
32
33
34 def pytest_addhooks(pluginmanager):
35 # Register new hooks from pytest_emoji.hooks
36 pluginmanager.add_hookspecs(hooks)
37
38
39 def pytest_report_teststatus(report, config):
40 if config.option.emoji is False:
41 # Do not modify reporting, unless pytest is called with --emoji
42 return
43
44 # Handle error and skipped in setup and teardown phase
45 if report.when in ("setup", "teardown"):
46 if report.failed:
47 short, verbose = config.hook.pytest_emoji_error(config=config)
48 return "error", short, verbose
49 elif report.skipped:
50 short, verbose = config.hook.pytest_emoji_skipped(config=config)
51 return "skipped", short, verbose
52
53 # Handle xfailed and xpassed
54 if hasattr(report, "wasxfail"):
55 if report.skipped:
56 short, verbose = config.hook.pytest_emoji_xfailed(config=config)
57 return "xfailed", short, verbose
58 elif report.passed:
59 short, verbose = config.hook.pytest_emoji_xpassed(config=config)
60 return "xpassed", short, verbose
61 else:
62 return "", "", ""
63
64 # Handle passed, skipped and failed in call phase
65 if report.when == "call":
66 if report.passed:
67 short, verbose = config.hook.pytest_emoji_passed(config=config)
68 elif report.skipped:
69 short, verbose = config.hook.pytest_emoji_skipped(config=config)
70 elif report.failed:
71 short, verbose = config.hook.pytest_emoji_failed(config=config)
72 return report.outcome, short, verbose
73
74
75 def pytest_addoption(parser):
76 group = parser.getgroup("emoji")
77 group.addoption(
78 "--emoji",
79 action="store_true",
80 default=False,
81 help="Add emojis to the test result log.",
82 )