0

I'm writing unit tests to make sure that my log messages for syslog are limited in size. In particular, my Formatter is set like this:

import logging
from logging.handlers import SysLogHandler
[...]
default_fmt = logging.Formatter(
    '%(name)s:%(levelname)s - %(message).{}s'.format(MAX_LOG_MESSAGE_SIZE)
)

All that I want to know is that the final message is less than a certain number of characters. I assumed I needed to patch SysLogHandler like this:

with patch('mylib.logger.logging.handlers.SysLogHandler') as m:
    import mylib.logger
    msg = 'foo'
    mylib.logger.debug(msg)
    print m.mock_calls
    print m.call_list()

However running the tests with nosetests doesn't work:

ImportError: No module named logging

What am I forgetting?

lorenzog
  • 3,483
  • 4
  • 29
  • 50
  • The `ImportError` suggests that the Python interpreter is unable to find the `logging` module. Are you using a pre-2.3 Python by chance? Otherwise, I'm stumped... – Kendas Dec 07 '15 at 15:12
  • @Kendas I'm on python 2.7.9. Yes, it's quite odd. – lorenzog Dec 07 '15 at 15:23

0 Answers0