Fixes #3630
This commit is contained in:
parent
a48c47b53b
commit
342f2cdc17
|
@ -392,7 +392,9 @@ class LoggingPlugin(object):
|
||||||
config, "log_file_date_format", "log_date_format"
|
config, "log_file_date_format", "log_date_format"
|
||||||
)
|
)
|
||||||
# Each pytest runtests session will write to a clean logfile
|
# Each pytest runtests session will write to a clean logfile
|
||||||
self.log_file_handler = logging.FileHandler(log_file, mode="w")
|
self.log_file_handler = logging.FileHandler(
|
||||||
|
log_file, mode="w", encoding="UTF-8"
|
||||||
|
)
|
||||||
log_file_formatter = logging.Formatter(
|
log_file_formatter = logging.Formatter(
|
||||||
log_file_format, datefmt=log_file_date_format
|
log_file_format, datefmt=log_file_date_format
|
||||||
)
|
)
|
||||||
|
|
|
@ -827,6 +827,40 @@ def test_log_file_ini_level(testdir):
|
||||||
assert "This log message won't be shown" not in contents
|
assert "This log message won't be shown" not in contents
|
||||||
|
|
||||||
|
|
||||||
|
def test_log_file_unicode(testdir):
|
||||||
|
log_file = testdir.tmpdir.join("pytest.log").strpath
|
||||||
|
|
||||||
|
testdir.makeini(
|
||||||
|
"""
|
||||||
|
[pytest]
|
||||||
|
log_file={}
|
||||||
|
log_file_level = INFO
|
||||||
|
""".format(
|
||||||
|
log_file
|
||||||
|
)
|
||||||
|
)
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
def test_log_file():
|
||||||
|
logging.getLogger('catchlog').info("Normal message")
|
||||||
|
logging.getLogger('catchlog').info("\u251c")
|
||||||
|
logging.getLogger('catchlog').info("Another normal message")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
result = testdir.runpytest()
|
||||||
|
|
||||||
|
# make sure that that we get a '0' exit code for the testsuite
|
||||||
|
assert result.ret == 0
|
||||||
|
assert os.path.isfile(log_file)
|
||||||
|
with open(log_file, encoding="utf-8") as rfh:
|
||||||
|
contents = rfh.read()
|
||||||
|
assert "Normal message" in contents
|
||||||
|
assert "\u251c" in contents
|
||||||
|
assert "Another normal message" in contents
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("has_capture_manager", [True, False])
|
@pytest.mark.parametrize("has_capture_manager", [True, False])
|
||||||
def test_live_logging_suspends_capture(has_capture_manager, request):
|
def test_live_logging_suspends_capture(has_capture_manager, request):
|
||||||
"""Test that capture manager is suspended when we emitting messages for live logging.
|
"""Test that capture manager is suspended when we emitting messages for live logging.
|
||||||
|
|
Loading…
Reference in New Issue