2009-09-30 228 views
0

nosetest是Turbogeras 2.0中的默認測試框架。該應用程序有一個初始化數據庫的websetup.py模塊。我使用MySQL我的開發和生產環境和websetup工作正常,但nosetest內存使用SQLite,當它試圖初始化數據庫發送一個錯誤:當發生這種情況,是如何判斷nosetest是否以編程方式運行

TypeError: SQLite Date, Time, and DateTime types only accept Python datetime objects as input.

我檢測in the import fase:

csvreader = csv.reader(open('res/products.csv'), delimiter=",", quotechar="'") 
for row in csvreader: 
    p = model.Product(row[1], row[2], row[3], row[4] + ".jpg") 
    # Even tried to convert the date to a sqlalchemy type 
    # need to put a conditional here, when testing I don't care this date 
    import sqlalchemy 
    dateadded = sqlalchemy.types.DateTime(row[5]) 
    p.dateAdded = dateadded 
    p.brand_id = row[6] 
    p.code = row[3] 

    ccat = model.DBSession.query(model.Category)\ 
     .filter(model.Category.id==int(row[8]) + 3).one() 

    p.categories.append(ccat) 

    p.normalPrice = row[9] 
    p.specialPrice = row[10] 
    p.discountPrice = row[11] 

    model.DBSession.add(p) 

如何判斷nosetest運行的時間?我已經嘗試:

if globals().has_key('ModelTest'): 

if vars().has_key('ModelTest'): 

第一個沒有結果和錯誤

回答

0

假設鼻子正在運行,「鼻子」頂層模塊將被導入。你應該能夠測試與

if 'nose' in sys.modules: 
    print "Nose is running, or at least has been imported!" 
    #or whatever you need to do if nose is running 

當然這不是一個簡單的測試,假設沒有其他原因,鼻子會被導入。

+0

這樣做!就在變量賦值之前,我把條件和現在我的鼻子測試再次工作。謝謝 – Juparave 2009-10-02 17:18:18

0

第二個我不使用TurboGears的,但有沒有設置或全球某處表明測試正在運行?在大型系統中,運行測試時通常需要進行小的更改。在SQLite和MySQL之間切換僅僅是一個例子。

+0

好吧,它必須在某個地方,我認爲ModelTest將是一個很好的標誌,但我是python和nosetest的新手。 – Juparave 2009-09-30 23:24:01

相關問題