Django: How to create a model dynamically just for testing

后端 未结 11 814
鱼传尺愫
鱼传尺愫 2020-12-02 05:15

I have a Django app that requires a settings attribute in the form of:

RELATED_MODELS = (\'appname1.modelname1.attribute1\',
                  \         


        
11条回答
  •  北海茫月
    2020-12-02 05:58

    Quoting from a related answer:

    If you want models defined for testing only then you should check out Django ticket #7835 in particular comment #24 part of which is given below:

    Apparently you can simply define models directly in your tests.py. Syncdb never imports tests.py, so those models won't get synced to the normal db, but they will get synced to the test database, and can be used in tests.

提交回复
热议问题