user2880391
user2880391

Reputation: 2781

Django - Print only errors when running all tests

We're using python - Django 1.10. We have more than 1000 tests. When running all the tests we're getting tons of logs to stdout. It mainly hurts on deployments - we're creating a docker instance and run all our tests (with python manage.py test). I would like to somehow print only errors when running all tests. Is there a way to do such thing?

Upvotes: 2

Views: 597

Answers (1)

Will Keeling
Will Keeling

Reputation: 22994

Perhaps create a test specific test_settings.py that overrides the log level with ERROR when the tests are run.

For example, if the main settings.py contains:

LOGGING = {
    ...
    'loggers': {
        'myapp': {
            'handlers': ['console', 'file'],
            'level': 'DEBUG',
        }
    }
}

Then you could create a test_settings.py that overrides the log level.

from settings import *

LOGGING['loggers']['myapp']['level'] = 'ERROR'

And then specify the test_settings when you run your tests.

python manage.py test --settings test_settings

Upvotes: 3

Related Questions