Detect django testing mode

后端 未结 6 858
逝去的感伤
逝去的感伤 2020-12-14 13:41

I\'m writing a reusable django app and I need to ensure that its models are only sync\'ed when the app is in test mode. I\'ve tried to use a custom DjangoTestRunner, but I f

6条回答
  •  我在风中等你
    2020-12-14 14:41

    Well, you can just simply use environment variables in this way:

    export MYAPP_TEST=1 && python manage.py test
    

    then in your settings.py file:

    import os
    
    TEST = os.environ.get('MYAPP_TEST')
    
    if TEST:
        # Do something
    

提交回复
热议问题