Skip to content

Commit

Permalink
support for python2.6 added
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Laskowski committed Jul 15, 2017
1 parent eac56d6 commit fe590b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions pytest_logger/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class Formatter(logging.Formatter):
logging.DEBUG: 'dbg',
}

def __init__(self, *args, **kwargs):
super(Formatter, self).__init__(*args, **kwargs)
def __init__(self, fmt):
logging.Formatter.__init__(self, fmt)
self._start = time.time()

def formatTime(self, record, datefmt=None):
Expand All @@ -161,7 +161,7 @@ def formatTime(self, record, datefmt=None):
def format(self, record):
record.levelshortname = Formatter.short_level_names.get(record.levelno,
'l%s' % record.levelno)
return super(Formatter, self).format(record)
return logging.Formatter.format(self, record)


@pytest.fixture
Expand Down Expand Up @@ -235,7 +235,7 @@ def _make_handlers(stdoutloggers, fileloggers, item):
def _make_stdout_handlers(loggers, fmt):
def make_handler(logger_and_level, fmt):
logger, level = logger_and_level
handler = logging.StreamHandler(stream=sys.stdout)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(fmt)
handler.setLevel(level)
handler.logger = logger
Expand Down
32 changes: 16 additions & 16 deletions tests/test_pytest_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ def test_file_handlers(testdir, conftest_py, test_case_py):
])

assert ls(basetemp(testdir), 'logs') == [test_case_py]
assert ls(basetemp(testdir), 'logs/{}'.format(test_case_py)) == ['test_case']
assert ls(basetemp(testdir), 'logs/{}/test_case'.format(test_case_py)) == ['bar', 'foo']
assert ls(basetemp(testdir), 'logs/{0}'.format(test_case_py)) == ['test_case']
assert ls(basetemp(testdir), 'logs/{0}/test_case'.format(test_case_py)) == ['bar', 'foo']

FileLineMatcher(basetemp(testdir), 'logs/{}/test_case/foo'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(basetemp(testdir), 'logs/{0}/test_case/foo'.format(test_case_py)).fnmatch_lines([
'* foo: this is fatal',
'* foo: this is warning',
])
FileLineMatcher(basetemp(testdir), 'logs/{}/test_case/bar'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(basetemp(testdir), 'logs/{0}/test_case/bar'.format(test_case_py)).fnmatch_lines([
'* bar: this is fatal',
])

Expand Down Expand Up @@ -408,7 +408,7 @@ def test_case{0}():
def test_logsdir_option(testdir, conftest_py, test_case_py):

logsdir = outdir(testdir, 'myinilogs')
result = testdir.runpytest('-s', '--logger-logsdir={}'.format(str(logsdir)))
result = testdir.runpytest('-s', '--logger-logsdir={0}'.format(str(logsdir)))
assert result.ret == 0
result.stdout.fnmatch_lines([
'',
Expand All @@ -418,13 +418,13 @@ def test_logsdir_option(testdir, conftest_py, test_case_py):

assert ls(logsdir) == [test_case_py]
assert ls(logsdir, test_case_py) == ['test_case']
assert ls(logsdir, '{}/test_case'.format(test_case_py)) == ['bar', 'foo']
assert ls(logsdir, '{0}/test_case'.format(test_case_py)) == ['bar', 'foo']

FileLineMatcher(logsdir, '{}/test_case/foo'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/foo'.format(test_case_py)).fnmatch_lines([
'* foo: this is fatal',
'* foo: this is warning',
])
FileLineMatcher(logsdir, '{}/test_case/bar'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/bar'.format(test_case_py)).fnmatch_lines([
'* bar: this is fatal',
])

Expand All @@ -434,7 +434,7 @@ def test_logsdir_ini(testdir, conftest_py, test_case_py):
logsdir = outdir(testdir, 'myinilogs')
makefile(testdir, ['pytest.ini'], """
[pytest]
logger_logsdir={}
logger_logsdir={0}
""".format(logsdir))

result = testdir.runpytest('-s')
Expand All @@ -447,13 +447,13 @@ def test_logsdir_ini(testdir, conftest_py, test_case_py):

assert ls(logsdir) == [test_case_py]
assert ls(logsdir, test_case_py) == ['test_case']
assert ls(logsdir, '{}/test_case'.format(test_case_py)) == ['bar', 'foo']
assert ls(logsdir, '{0}/test_case'.format(test_case_py)) == ['bar', 'foo']

FileLineMatcher(logsdir, '{}/test_case/foo'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/foo'.format(test_case_py)).fnmatch_lines([
'* foo: this is fatal',
'* foo: this is warning',
])
FileLineMatcher(logsdir, '{}/test_case/bar'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/bar'.format(test_case_py)).fnmatch_lines([
'* bar: this is fatal',
])

Expand All @@ -464,7 +464,7 @@ def test_logsdir_cleanup(testdir, conftest_py, test_case_py):

makefile(testdir, ['pytest.ini'], """
[pytest]
logger_logsdir={}
logger_logsdir={0}
""".format(logsdir))

logsdir.ensure('tmpfile').write('\n'.join(Source('this shall be removed')))
Expand All @@ -480,12 +480,12 @@ def test_logsdir_cleanup(testdir, conftest_py, test_case_py):

assert ls(logsdir) == [test_case_py]
assert ls(logsdir, test_case_py) == ['test_case']
assert ls(logsdir, '{}/test_case'.format(test_case_py)) == ['bar', 'foo']
assert ls(logsdir, '{0}/test_case'.format(test_case_py)) == ['bar', 'foo']

FileLineMatcher(logsdir, '{}/test_case/foo'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/foo'.format(test_case_py)).fnmatch_lines([
'* foo: this is fatal',
'* foo: this is warning',
])
FileLineMatcher(logsdir, '{}/test_case/bar'.format(test_case_py)).fnmatch_lines([
FileLineMatcher(logsdir, '{0}/test_case/bar'.format(test_case_py)).fnmatch_lines([
'* bar: this is fatal',
])
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tox]
envlist =
check,
{py27,py34,py35,pypy}-pytest{29,30},
{py26,py27,py35,py36,pypy}-pytest{30,31},
docs

[testenv]
deps =
pytest29: pytest==2.9.*
pytest30: pytest==3.0.*
pytest31: pytest==3.1.*
pytest-xdist
commands =
py.test {posargs} --tb=short -x --strict tests
Expand Down

0 comments on commit fe590b9

Please sign in to comment.