Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Hugo Martins 2018-07-03 23:11:35 +01:00
commit f52a5d3be2
7 changed files with 58 additions and 3 deletions

View File

@ -0,0 +1 @@
Log messages with unicode characters would not appear in the output log file.

View File

@ -0,0 +1 @@
No longer raise AttributeError when legacy marks can't be stored.

View File

@ -392,7 +392,9 @@ class LoggingPlugin(object):
config, "log_file_date_format", "log_date_format"
)
# 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_format, datefmt=log_file_date_format
)

View File

@ -259,7 +259,7 @@ def store_legacy_markinfo(func, mark):
if holder is None:
holder = MarkInfo.for_mark(mark)
setattr(func, mark.name, holder)
else:
elif isinstance(holder, MarkInfo):
holder.add_mark(mark)

View File

@ -22,7 +22,7 @@ def monkeypatch():
monkeypatch.setitem(mapping, name, value)
monkeypatch.delitem(obj, name, raising=True)
monkeypatch.setenv(name, value, prepend=False)
monkeypatch.delenv(name, value, raising=True)
monkeypatch.delenv(name, raising=True)
monkeypatch.syspath_prepend(path)
monkeypatch.chdir(path)

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import re
import os
from io import open
import six
@ -827,6 +828,43 @@ def test_log_file_ini_level(testdir):
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(
"""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
def test_log_file():
logging.getLogger('catchlog').info("Normal message")
logging.getLogger('catchlog').info("")
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 u"" in contents
assert "Another normal message" in contents
@pytest.mark.parametrize("has_capture_manager", [True, False])
def test_live_logging_suspends_capture(has_capture_manager, request):
"""Test that capture manager is suspended when we emitting messages for live logging.

View File

@ -63,6 +63,19 @@ class TestMark(object):
mark.hello(f)
assert f.hello
def test_mark_legacy_ignore_fail(self):
def add_attribute(func):
func.foo = 1
return func
@pytest.mark.foo
@add_attribute
def test_fun():
pass
assert test_fun.foo == 1
assert test_fun.pytestmark
@ignore_markinfo
def test_pytest_mark_keywords(self):
mark = Mark()