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 回答