2015-12-24 248 views

回答

1

是的,這是一個有效的方法。

每個應用程序都有自己的factories.py文件,其中包含工廠的自己的模型。如果應用程序還依賴於其他應用程序的模型,則可以從原始應用程序導入它們以保持乾燥。

實施例:

app1 
|__ factories.py 
app2 
|__ factories.py 
app3 
|__ tests.py  # Tests interaction of app3 with app1 and app2 
|__ factories.py # Define factories for app3's models only 
       # and reuse factories from app1 and app2 
       # for their models 

# app3/tests.py 

from app1.factories import Model1 
from app2.factories import Model2 
from app3.factories import Model3 

def test_feature_in_app3(): 
    # do something with Model1, Model2 and Model3 
相關問題