检测django测试模式 [英] Detect django testing mode
本文介绍了检测django测试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以有没有人知道如何做?
编辑
这是我如何做:
#in settings.py
import sys
TEST ='测试'在sys.argv
希望它有帮助。
解决方案
我认为这里提供的答案是 https://stackoverflow.com/a/ 7651002/465673 是一个更干净的方法:
将其放在您的settings.py中:
import sys
TESTING = sys.argv [1:2] == ['test']
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 found no examples of how to do that (the documentation only shows how to define a custom test runner).
So, does anybody have an idea of how to do it?
EDIT
Here's how I'm doing it:
#in settings.py
import sys
TEST = 'test' in sys.argv
Hope it helps.
解决方案
I think the answer provided here https://stackoverflow.com/a/7651002/465673 is a much cleaner way of doing it:
Put this in your settings.py:
import sys
TESTING = sys.argv[1:2] == ['test']
这篇关于检测django测试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文