File tree 3 files changed +42
-1
lines changed
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change
1
+ Log messages with unicode characters would not appear in the output log file.
Original file line number Diff line number Diff line change @@ -392,7 +392,9 @@ def __init__(self, config):
392
392
config , "log_file_date_format" , "log_date_format"
393
393
)
394
394
# Each pytest runtests session will write to a clean logfile
395
- self .log_file_handler = logging .FileHandler (log_file , mode = "w" )
395
+ self .log_file_handler = logging .FileHandler (
396
+ log_file , mode = "w" , encoding = "UTF-8"
397
+ )
396
398
log_file_formatter = logging .Formatter (
397
399
log_file_format , datefmt = log_file_date_format
398
400
)
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
import re
3
3
import os
4
+ from io import open
4
5
5
6
import six
6
7
@@ -827,6 +828,43 @@ def test_log_file(request):
827
828
assert "This log message won't be shown" not in contents
828
829
829
830
831
+ def test_log_file_unicode (testdir ):
832
+ log_file = testdir .tmpdir .join ("pytest.log" ).strpath
833
+
834
+ testdir .makeini (
835
+ """
836
+ [pytest]
837
+ log_file={}
838
+ log_file_level = INFO
839
+ """ .format (
840
+ log_file
841
+ )
842
+ )
843
+ testdir .makepyfile (
844
+ """
845
+ # -*- coding: utf-8 -*-
846
+ from __future__ import unicode_literals
847
+ import logging
848
+
849
+ def test_log_file():
850
+ logging.getLogger('catchlog').info("Normal message")
851
+ logging.getLogger('catchlog').info("├")
852
+ logging.getLogger('catchlog').info("Another normal message")
853
+ """
854
+ )
855
+
856
+ result = testdir .runpytest ()
857
+
858
+ # make sure that that we get a '0' exit code for the testsuite
859
+ assert result .ret == 0
860
+ assert os .path .isfile (log_file )
861
+ with open (log_file , encoding = "utf-8" ) as rfh :
862
+ contents = rfh .read ()
863
+ assert "Normal message" in contents
864
+ assert u"├" in contents
865
+ assert "Another normal message" in contents
866
+
867
+
830
868
@pytest .mark .parametrize ("has_capture_manager" , [True , False ])
831
869
def test_live_logging_suspends_capture (has_capture_manager , request ):
832
870
"""Test that capture manager is suspended when we emitting messages for live logging.
You can’t perform that action at this time.
0 commit comments