Skip to content

problems with unicode characters when saving log to file #3630

@Sup3rGeo

Description

@Sup3rGeo

Normal case

I have this very simple test which is just logging some unicode character:

test_log.py

import logging

logger = logging.getLogger(__name__)

def test():
    logger.info("Normal")
    logger.info("\u251c")
    logger.info("Also normal")

And when I run it using --log-cli-level=INFO then I get this terminal output, which is fine:

============================= test session starts =============================
platform win32 -- Python 3.6.3, pytest-3.6.2, py-1.5.4, pluggy-0.6.0 -- c:\users\victor\desktop\pytest unicode bug\venv\scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\Victor\Desktop\pytest unicode bug, inifile:
collected 1 item                                                               

test_log.py::test
-------------------------------- live log call --------------------------------
test_log.py                  6 INFO     Normal
test_log.py                  7 INFO     ├
test_log.py                  8 INFO     Also normal
PASSED                                                                   [100%]

========================== 1 passed in 0.02 seconds ===========================


Save to file

However, when I also run with --log-file=logoutput, this is what I get:

logoutput contents:

test_log.py                  6 INFO     Normal
test_log.py                  8 INFO     Also normal

So it seems that the lines with unicode characters are not getting printed in the log file, which is a problem.

Environment details

  • pytest 3.6.2
  • Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: loggingrelated to the logging builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions