-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Colorize the levelname column in the live-log output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
import py.io | ||
from _pytest.logging import ColoredLevelFormatter | ||
|
||
|
||
def test_coloredlogformatter(): | ||
logfmt = '%(filename)-25s %(lineno)4d %(levelname)-8s %(message)s' | ||
|
||
record = logging.LogRecord( | ||
name='dummy', level=logging.INFO, pathname='dummypath', lineno=10, | ||
msg='Test Message', args=(), exc_info=False) | ||
|
||
class ColorConfig(object): | ||
class option(object): | ||
pass | ||
|
||
tw = py.io.TerminalWriter() | ||
tw.hasmarkup = True | ||
formatter = ColoredLevelFormatter(tw, logfmt) | ||
output = formatter.format(record) | ||
assert output == ('dummypath 10 ' | ||
'\x1b[32mINFO \x1b[0m Test Message') | ||
|
||
tw.hasmarkup = False | ||
formatter = ColoredLevelFormatter(tw, logfmt) | ||
output = formatter.format(record) | ||
assert output == ('dummypath 10 ' | ||
'INFO Test Message') |