我正在使用Satchmo購物車軟件在Django項目上工作。我必須爲這個項目使用相當複雜的自定義代碼,因此想要讓所有的Django和Satchmo測試都通過。Satchmo單元測試只能隔離運行
但是,其中一個測試只能單獨使用,具體來說就是custom.ShopTest.test_custom_product
的product/modules/custom/tests.py
。該測試獨立運作(即與./manage.py test custom.ShopTest
),但不是當我一起運行所有測試(./manage.py test
)。
此測試使用Django測試客戶端打開主頁,並在頁面上包含某些文本時聲明。當我在生產數據庫中加載相同的夾具時,這些文本也在頁面上。
另外,當測試開始時,標題應顯示在頁面上的產品也存在於測試數據庫中,因此夾具加載正確。
我認爲其他一些Satchmo應用程序以某種方式破壞了測試,但我一直認爲Django儘可能單獨運行測試。
編輯:
失敗測試輸出是:
======================================================================
FAIL: test_custom_product (product.modules.custom.tests.ShopTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/data/Projects/satchmo/satchmo/apps/product/modules/custom/tests.py", line 43, in test_custom_product
self.assertContains(response, "Computer", count=1)
File "/data/PythonEnvironments/mywebsite.nl/local/lib/python2.7/site-packages/django/test/testcases.py", line 427, in assertContains
" (expected %d)" % (real_count, text, count))
AssertionError: Found 0 instances of 'Computer' in response (expected 1)
----------------------------------------------------------------------
編輯2: 我剛剛發現測試時,我把一個斷點在請求的視圖功能並不總是發生,等待一段時間後再繼續調試程序停止在斷點處。也許這與線程有關?
失敗測試的輸出將會有所幫助。 – AdamKG 2012-01-12 21:25:31
我已經添加了輸出。 – muksie 2012-01-13 09:27:07