Disable logging during the manage.py test?

I am using the standard python registration module. When I call python manage.py test , I would like to disable logging before all tests are run. Is there any signal or some other hook that I could use to call logging.disable? Or is there any other way to disable logging when running python manage.py test ?

+7
python django logging
source share
7 answers

The only way I know is to edit manage.py myself ... not very elegant, of course, but at least it should bring you to where you need to be.

+2
source share

Actually there is a much better way to do this: django-nose is kwarg:

Just run:

 ./bin/manage.py test --logging-clear-handlers 
+12
source share

As a simple alternative, you can turn off logging when running tests in your settings file as follows:

 if 'test' in sys.argv: logger.removeHandler(handler) logger.setLevel(logging.ERROR) 
+9
source share

The simplest thing I used:

 import logging class MyTestClass(TestCase): def setUp(self): logging.disable(logging.CRITICAL) 

It does not require editing, correction, additional installations, etc. All entries are completely disabled.

+5
source share

I prefer to run tests using separate settings_test.py, where I can remove unnecessary applications, middleware and other materials that I do not need during testing. And I can disable the log output here as follows:

 from settings import * import logging # direct all logging output to nowhere class NullHandler(logging.Handler): def emit(self, record): pass logging.getLogger().addHandler(NullHandler()) 
+4
source share

I also fixed test_extensions .

+1
source share

If you are using django-nose , you can add the snippet below to your settings.py file to disable log output at startup ./manage.py test

 NOSE_ARGS = [ '--nologcapture' ] 
0
source share

All Articles