2017-08-15 19 views
0

我必須改變.clean()它背後有深刻的邏輯場景。
由於它與我的功能沒有直接關係,我決定嘲笑它並削減複雜的邏輯。然後我可以使用mommy.make來完成測試對象。
爲什麼模擬模型方法失敗時運行全套房

這是我的代碼。
https://gist.github.com/elcolie/cfeadfbb29996823abfb998447cfe822

如果我單獨運行它們,它的工作原理。但是在運行完整套件時失敗。

我不得不請按照下列:
why would a django test fail only when the full test suite is run?
Django unit tests failing when run with other test cases
但不起作用。

我的錯誤: 2最後的測試情況下未能

Failure 
Traceback (most recent call last): 
    File "/Users/el/.pyenv/versions/3.6.0/lib/python3.6/unittest/mock.py", line 1179, in patched 
    return func(*args, **keywargs) 
    File "/Users/el/Code/eneos-pos-web/eneos/apps/mail_logs/mail_data_tests.py", line 194, in test_user_change_status_13July_query_all_false 
    self.assertDictEqual(expected_obj, summary) 
AssertionError: {'tod[71 chars] 0, 'today_active_email_true': 0, 'today_active_email_none': 1} != {'tod[71 chars] 0, 'today_active_email_true': 0, 'today_active_email_none': 0} 
    {'today_active_email': 1, 
    'today_active_email_false': 0, 
- 'today_active_email_none': 1, 
?       ^

+ 'today_active_email_none': 0, 
?       ^

    'today_active_email_true': 0, 
    'today_all_orders': 1} 


Failure 
Traceback (most recent call last): 
    File "/Users/el/.pyenv/versions/3.6.0/lib/python3.6/unittest/mock.py", line 1179, in patched 
    return func(*args, **keywargs) 
    File "/Users/el/Code/eneos-pos-web/eneos/apps/mail_logs/mail_data_tests.py", line 231, in test_user_change_status_16July 
    self.assertDictEqual(expected_obj, summary) 
AssertionError: {'today_active_email': 1, 'today_active_email_fals[84 chars]': 1} != {'today_all_orders': 1, 'today_active_email': 1, '[84 chars]': 0} 
    {'today_active_email': 1, 
    'today_active_email_false': 0, 
- 'today_active_email_none': 1, 
?       ^

+ 'today_active_email_none': 0, 
?       ^

    'today_active_email_true': 0, 
    'today_all_orders': 1} 

回答

0

我相信程序邏輯沒有與序列ID爲界。
但是,要像單獨運行一樣將數據庫恢復到原始狀態。
我使用下面的配置。

class MailLogFixture(TransactionTestCase): 
    reset_sequences = True 

和它的作品