Skip to content Skip to sidebar Skip to footer

Mocked Unit Test Raises A "stop Called On Unstarted Patcher" Error

When running the test bellow, I got a stop called on unstarted patcher. def test_get_subvention_internal_no_triggered_admission(self): billing_cluster = BillingClusterFactory()

Solution 1:

In short, you cannot patch the builtins func hasattr

patch('builtins.hasattr', return_value=False)

reason: used by mock.py

ifnot _is_started(self):
    raise RuntimeError('stop called on unstarted patcher')

def_is_started(patcher):
    # XXXX horriblereturnhasattr(patcher, 'is_local')

to repeat the error:

@mock.patch('__builtin__.hasattr')
def test_mock_hasattr(self, mocked_hasattr):
    # aslongas it issettoFalse, it will trigger
    mocked_hasattr.return_value = False

to mock a builtins func inside models.py:

# narrow the mock scope@mock.patch('orders.models.hasattr')

Post a Comment for "Mocked Unit Test Raises A "stop Called On Unstarted Patcher" Error"