Nose test does not work when Unittest is not

We see a strange difference between Python nose test results against unittests. Here is the code that causes the problem, in particular the last line:

import logging

class ClassThatLogsBadly:
    log = logging.getLogger(__name__)

    def method_that_logs_badly(self):
        self.log.error('A message', 'Another string')
        return ('I ran')

The above logis retrieved from the Python protocol library and creates a problem when called because of the following (from the Python library:) logging/__init__.py:328:

def getMessage(self):
    """
    Return the message for this LogRecord.

    Return the message for this LogRecord after merging any user-supplied
    arguments with the message.
    """
    msg = str(self.msg)
    if self.args:
        msg = msg % self.args
    return msg

As you can see, he is trying to connect in Another stringwith A message, but the latter does not have valid slots (of type %s) so that he cannot execute it. This is a known issue , and the solution is to format your material outside the registrar. However, our problem is testing to make sure that this is done.

, unittest py.test, . , . py.test, , : , - , .

Python 3.4. , :

import logging
import unittest

from mycode import ClassThatLogsBadly

class TestClassThatLogsBadly(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_method_that_logs_badly(self):
        clz = ClassThatLogsBadly()
        result = clz.method_that_logs_badly()
        self.assertEquals('I ran', result)
+4
1

, . , , self.log, ( " " mycode "). , , :

<--""
   Level WARNING
   |
   o<--"mycode"
       Level NOTSET so inherits level WARNING

, log.error, unittest py.test.

nose , , log.error .

, logging.basicConfig() ClassThatLogsBadly log . , unittest, py.test .

, : , , .

+2

All Articles