2

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?

user2880391
  • 2,683
  • 7
  • 38
  • 77
  • 1
    Do you have a `LOGGING` section in your `settings.py` that controls the logging for your application? This normally determines the apps that you have set to log, and the level at which they log. – Will Keeling Apr 22 '18 at 09:30
  • I do. We have one logger set to write to console and file. The question is how to make this logger write only errors when running all tests. – user2880391 Apr 22 '18 at 10:21

1 Answers1

3

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
Will Keeling
  • 22,055
  • 4
  • 51
  • 61
  • thanks @Will Keeling. I'm getting 'No Module names test_settings'. Am I missing something? (I added the file next to out settings.py) – user2880391 Apr 23 '18 at 10:50
  • @user2880391 you should supply the fully qualified package name, so `--settings app.package.test_settings`. Sorry should have been clearer in my answer. – Will Keeling Apr 23 '18 at 10:53
  • Thanks. I think that's a good idea, though following you answer I decided to use the log level as an environment variable and set it as 'ERROR' in the script that is used to run the tests. – user2880391 Apr 23 '18 at 12:02