0

I have multiple unit_test files created in my project. When i run all the test files independtely, all files passes all the test cases.

But when i run all the test through TestRunner, i get error as

TypeError: 'NoneType' object is not callable.

I have noticed that this error is thrown because of patching.

======================================================================
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

...

Code Snippet:

@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)

1
  • It looks like you're setting up your mocks incorrectly. I can't really be sure though without looking through your entire source code. I'm kind of unclear about why you're mocking a class, but then calling a function and expecting it to be mocked. Maybe look at your code a little more closely and spend some time debugging. Commented Aug 3, 2013 at 8:32

1 Answer 1

2

We had the similiar problem in our unit testing framework. If the method that you are testing through unit test has the decorator "transaction.commit_manually", you need to have the same decorator in the unit test method. Otherwise you get this excpetion "None type object is not callable" which will give no clue about the actual issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.