def test_run(self): """ run function with exception raise """ from wsgi import run import modules def mock_store(label, subj, body): """ emulate exception raise """ raise Exception(''.join([label, subj, body])) saved = modules.store modules.store = mock_store with self.assertRaises(Exception) as context: run('store', 'xxx') assert 'xxx' in str(context.exception) modules.store = saved
def main(): wsgi.run()
import sys from wsgi import run from models import create_model # python manage.py xx xx2 命令行输入 # 执行py文件时,后面携带的参数, #可以通过py文件中的sys模块的sys.argv这个属性拿到, #是个列表,列表第一项是文件名称,第二项之后,都是携带的参数 commands = sys.argv # xx xx2 # ['manage.py', 'xx', 'oo'] # 运行项目的指令: python manage.py runserver # 数据库同步指令: python manage.py migrate 建表 a1 = commands[1] if a1 == 'runserver': run() elif a1 == 'migrate': create_model()
def run(): wsgi.run()