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?

2
  • 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. Commented Apr 22, 2018 at 9: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. Commented Apr 22, 2018 at 10:21

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

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 you should supply the fully qualified package name, so --settings app.package.test_settings. Sorry should have been clearer in my answer.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.