How can I disable logging while running unit tests in Python Django?

后端 未结 15 774
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 09:50

I am using a simple unit test based test runner to test my Django application.

My application itself is configured to use a basic logger in settings.py using:

<
15条回答
  •  失恋的感觉
    2020-12-07 10:31

    You can put this in the top level directory for unit tests __init__.py file. This will disable logging globally in the unit test suite.

    # tests/unit/__init__.py
    import logging
    
    logging.disable(logging.CRITICAL)
    

提交回复
热议问题