[Fixed]-Stop nosetests from printing logging information?

33👍

Thanks to those who provided an answer to my question. I chose not to implement @amezhenin‘s solution as it was too different from how I run my tests and I didn’t want to change. @Oleksiy‘s solutions got rid of some logging messages but not all of them. I didn’t quite get what @gardenunez was getting at but that’s my fault.

After more research, I realized that I was specifying the nosetest argument incorrectly. It’s not --nocapture as I indicated in my initial question but rather --nologcapture. When I specified this argument, all of my logging messages were hidden.

👤Jim

6👍

You can always run nose with --logging-clear-handlers to clear all other logging handlers.

3👍

I can suggest you to put something like this into your settings.py:

if 'test' in sys.argv:
    # disable loggers output
    LOGGING["loggers"] = {}

btw, I using nose and doctests for testing purposes so my full template looks like this:

if 'test' in sys.argv:
    # add Nose to INSTALLED_APPS for running tests
    INSTALLED_APPS = INSTALLED_APPS + ('django_nose',)
    TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
    NOSE_ARGS = ['--with-doctest']
    # change DB to sqlite3, when running test for speedup
    DATABASES['default'] = {'ENGINE': 'django.db.backends.sqlite3'}
    # disable loggers output
    LOGGING["loggers"] = {}

UPD. Forgot to tell that I run test with python manage.py test, that is why I can refer to 'test' in sys.argv.

0👍

Try this:

logging.disable(logging.CRITICAL) or logging.disable(logging.NOTSET)

It will disable logging calls with the specified severity level.

Leave a comment