0

プロジェクトに複数の unit_test ファイルを作成しました。すべてのテスト ファイルを個別に実行すると、すべてのファイルがすべてのテスト ケースに合格します。

しかし、TestRunner を使用してすべてのテストを実行すると、次のようなエラーが発生します。

TypeError: 'NoneType' object is not callable.

パッチが適用されたためにこのエラーがスローされることに気付きました。

======================================================================
ERROR [0.001s]: test_create_pull_requests (test_custom_logs_manager.TestCustomLogManager)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/x/local/dmali/githome/am-repo/unit_tests/lib/mock/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/x/local/dmali/githome/am-repo/unit_tests/data_process/caldata/test_custom_logs_manager.py", line 71, in test_create_pull_requests
    cal_handlers)
TypeError: 'NoneType' object is not callable

...

コードスニペット:

@patch('data_process.caldata.custom_logs_manager.CustomLogsPullTrack',
       MagicMock(return_value = MockCustomLogsPullTrack()))
def test_create_pull_requests(self):
    """
    Unit Test for create_pull_requests
    """
    report_times = [datetime.datetime.now()]
    group_id = 1
    data_center = MockDataCenterCalLoc()
    data_center_cal_loc_id = 1
    mock_pull_config = MockPayMonCalBizConfig()
    mock_pull_config.id = 1
    cal_handlers = {'TEST_CAL': 'TEST_CLASS'}
    result = custom_logs_manager.create_pull_requests(report_times,
                                                      group_id,
                                                      data_center,
                                                      data_center_cal_loc_id,
                                                      mock_pull_config,
                                                      cal_handlers)

    self.assertEqual(result[0].paymon_calbiz_config_id, 1)
    self.assertEqual(result[0].pool_name, 'TEST')
    self.assertEqual(result[0].data_center_cal_loc_id, 1)

4

1 に答える 1

2

単体テスト フレームワークにも同様の問題がありました。単体テストでテストしているメソッドに「transaction.commit_manually」デコレータがある場合、単体テスト メソッドにも同じデコレータが必要です。そうしないと、「None type object is not callable」という例外が発生し、実際の問題についての手がかりが得られません。

于 2013-08-05T22:28:34.307 に答える