3

I'm using the LogCapture object from testfixtures to unit test logging statements. Works wonderfully.

However, during my test suite, logs are actually being emitted to the console (messy for Jenkins) and, worse, to Sentry!

I don't want to have to override the LOGGING setting; this seems to undermine the test itself. How can I prevent these emissions while still capturing logs?

Ben
  • 51,770
  • 36
  • 127
  • 149
jMyles
  • 11,772
  • 6
  • 42
  • 56
  • 1
    Is this an option: check for `if 'test' in sys.argv:` in `settings.py` and turn off console and sentry loggers? – alecxe Sep 13 '13 at 21:32
  • 1
    check my answer here: http://stackoverflow.com/questions/5255657/how-can-i-disable-logging-while-running-unit-tests-in-python-django/7732916#7732916 – Hassek Sep 13 '13 at 22:00
  • @Hassek: I love your answer (and looked at it before asking this question), but it doesn't apply to this scenario. I don't want to disable logging precisely because I want to capture it for use in my unit test. Instead, I want to simply silence emission. – jMyles Sep 15 '13 at 19:41
  • oh interesting, if you ever find something about it let me know, but my wild guess is that you need to add that silence functionality to the logs configuration when the test begin. – Hassek Sep 16 '13 at 21:00

1 Answers1

0

Have you considered using the mock library?

https://pypi.python.org/pypi/mock/

This will let you "fake" the call sentry and still track what it logs.

guyrt
  • 927
  • 7
  • 12