From 56f5ce6ee199a3724264ecbd350865bbf2ed762c Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sun, 18 Oct 2015 14:09:22 +0100 Subject: [PATCH] [Tests] Properly test for DeprecationWarning in test_log --- deluge/tests/test_log.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/deluge/tests/test_log.py b/deluge/tests/test_log.py index feda208fa..ab64e0655 100644 --- a/deluge/tests/test_log.py +++ b/deluge/tests/test_log.py @@ -1,22 +1,32 @@ -import logging +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015 Calum Lind +# Copyright (C) 2010 Pedro Algarvio +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# -from twisted.internet import defer -from twisted.trial import unittest +import logging +import warnings from deluge.log import setup_logger +from .basetest import BaseTestCase -class LogTestCase(unittest.TestCase): - def setUp(self): # NOQA + +class LogTestCase(BaseTestCase): + def set_up(self): setup_logger(logging.DEBUG) - def tearDown(self): # NOQA + def tear_down(self): setup_logger("none") def test_old_log_deprecation_warning(self): - import warnings from deluge.log import LOG - d = defer.Deferred() - d.addCallback(LOG.debug, "foo") - self.assertFailure(d, DeprecationWarning) - warnings.resetwarnings() + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + LOG.debug("foo") + self.assertEqual(w[-1].category, DeprecationWarning)