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?
1 Answer
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
3 Comments
user2880391
thanks @Will Keeling. I'm getting 'No Module names test_settings'. Am I missing something? (I added the file next to out settings.py)
Will Keeling
@user2880391 you should supply the fully qualified package name, so
--settings app.package.test_settings. Sorry should have been clearer in my answer.user2880391
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.
LOGGINGsection in yoursettings.pythat controls the logging for your application? This normally determines the apps that you have set to log, and the level at which they log.