From 5841a3d789bdbb4c1647b47842a97e6a66accdde Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Sun, 17 Sep 2017 14:28:18 +0200 Subject: [PATCH] Remove pytest-capturelog backward compat code --- _pytest/logging.py | 73 +-------------------- testing/logging/test_capturelog_compat.py | 80 ----------------------- testing/logging/test_fixture.py | 26 -------- 3 files changed, 1 insertion(+), 178 deletions(-) delete mode 100644 testing/logging/test_capturelog_compat.py diff --git a/_pytest/logging.py b/_pytest/logging.py index 57ed4035b10..01579404f05 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -2,7 +2,6 @@ import logging from contextlib import closing, contextmanager -import functools import sys import pytest @@ -207,76 +206,6 @@ def at_level(self, level, logger=None): logger.setLevel(orig_level) -class CallablePropertyMixin(object): - """Backward compatibility for functions that became properties.""" - - @classmethod - def compat_property(cls, func): - if isinstance(func, property): - make_property = func.getter - func = func.fget - else: - make_property = property - - @functools.wraps(func) - def getter(self): - naked_value = func(self) - ret = cls(naked_value) - ret._naked_value = naked_value - ret._warn_compat = self._warn_compat - ret._prop_name = func.__name__ - return ret - - return make_property(getter) - - def __call__(self): - new = "'caplog.{0}' property".format(self._prop_name) - if self._prop_name == 'records': - new += ' (or caplog.clear())' - self._warn_compat(old="'caplog.{0}()' syntax".format(self._prop_name), - new=new) - return self._naked_value # to let legacy clients modify the object - - -class CallableList(CallablePropertyMixin, list): - pass - - -class CallableStr(CallablePropertyMixin, py.builtin.text): - pass - - -class CompatLogCaptureFixture(LogCaptureFixture): - """Backward compatibility with pytest-capturelog.""" - - def _warn_compat(self, old, new): - self._item.warn(code='L1', - message=("{0} is deprecated, use {1} instead" - .format(old, new))) - - @CallableStr.compat_property - def text(self): - return super(CompatLogCaptureFixture, self).text - - @CallableList.compat_property - def records(self): - return super(CompatLogCaptureFixture, self).records - - @CallableList.compat_property - def record_tuples(self): - return super(CompatLogCaptureFixture, self).record_tuples - - def setLevel(self, level, logger=None): - self._warn_compat(old="'caplog.setLevel()'", - new="'caplog.set_level()'") - return self.set_level(level, logger) - - def atLevel(self, level, logger=None): - self._warn_compat(old="'caplog.atLevel()'", - new="'caplog.at_level()'") - return self.at_level(level, logger) - - @pytest.fixture def caplog(request): """Access and control log capturing. @@ -287,7 +216,7 @@ def caplog(request): * caplog.records() -> list of logging.LogRecord instances * caplog.record_tuples() -> list of (logger_name, level, message) tuples """ - return CompatLogCaptureFixture(request.node) + return LogCaptureFixture(request.node) def get_actual_log_level(config, setting_name): diff --git a/testing/logging/test_capturelog_compat.py b/testing/logging/test_capturelog_compat.py deleted file mode 100644 index 0c527b5878d..00000000000 --- a/testing/logging/test_capturelog_compat.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- -import pytest - - -def test_camel_case_aliases(testdir): - testdir.makepyfile(''' - import logging - - logger = logging.getLogger(__name__) - - def test_foo(caplog): - caplog.setLevel(logging.INFO) - logger.debug('boo!') - - with caplog.atLevel(logging.WARNING): - logger.info('catch me if you can') - ''') - result = testdir.runpytest() - assert result.ret == 0 - - with pytest.raises(pytest.fail.Exception): - result.stdout.fnmatch_lines(['*- Captured *log call -*']) - - result = testdir.runpytest('-rw') - assert result.ret == 0 - result.stdout.fnmatch_lines(''' - =*warning* summary*= - *caplog.setLevel()*deprecated* - *caplog.atLevel()*deprecated* - ''') - - -def test_property_call(testdir): - testdir.makepyfile(''' - import logging - - logger = logging.getLogger(__name__) - - def test_foo(caplog): - logger.info('boo %s', 'arg') - - assert caplog.text == caplog.text() == str(caplog.text) - assert caplog.records == caplog.records() == list(caplog.records) - assert (caplog.record_tuples == - caplog.record_tuples() == list(caplog.record_tuples)) - ''') - result = testdir.runpytest() - assert result.ret == 0 - - result = testdir.runpytest('-rw') - assert result.ret == 0 - result.stdout.fnmatch_lines(''' - =*warning* summary*= - *caplog.text()*deprecated* - *caplog.records()*deprecated* - *caplog.record_tuples()*deprecated* - ''') - - -def test_records_modification(testdir): - testdir.makepyfile(''' - import logging - - logger = logging.getLogger(__name__) - - def test_foo(caplog): - logger.info('boo %s', 'arg') - assert caplog.records - assert caplog.records() - - del caplog.records()[:] # legacy syntax - assert not caplog.records - assert not caplog.records() - - logger.info('foo %s', 'arg') - assert caplog.records - assert caplog.records() - ''') - result = testdir.runpytest() - assert result.ret == 0 diff --git a/testing/logging/test_fixture.py b/testing/logging/test_fixture.py index bdfa67ecc90..4072234d89f 100644 --- a/testing/logging/test_fixture.py +++ b/testing/logging/test_fixture.py @@ -71,29 +71,3 @@ def test_clear(caplog): assert len(caplog.records) caplog.clear() assert not len(caplog.records) - - -def test_special_warning_with_del_records_warning(testdir): - p1 = testdir.makepyfile(""" - def test_del_records_inline(caplog): - del caplog.records()[:] - """) - result = testdir.runpytest_subprocess(p1) - result.stdout.fnmatch_lines([ - "*'caplog.records()' syntax is deprecated," - " use 'caplog.records' property (or caplog.clear()) instead", - "*1 *warnings*", - ]) - - -def test_warning_with_setLevel(testdir): - p1 = testdir.makepyfile(""" - def test_inline(caplog): - caplog.setLevel(0) - """) - result = testdir.runpytest_subprocess(p1) - result.stdout.fnmatch_lines([ - "*'caplog.setLevel()' is deprecated," - " use 'caplog.set_level()' instead", - "*1 *warnings*", - ])