【发布时间】:2017-09-04 10:27:39
【问题描述】:
## tests file
@mock.patch('profiles.models.create_stripe_charge', StripeMocks._mock_raises_stripe_error)
def my_test(self):
# ... stuff
## logic file
def create_stripe_charge(customer, amount_in_cents, capture=True):
# ... stuff
## mocks file
class StripeMocks:
def _mock_raises_stripe_error(self):
raise stripe.error.StripeError
在运行我的测试时,我收到了 _mock_raises_stripe_error() takes 1 positional argument but 3 were given' 错误。
我知道我正在尝试使用 1-arg 方法模拟 3-args 方法,但如果我只想告诉 Python 怎么办:请,无论我的 create_stripe_charge 方法有多少参数,我只是想模拟它引发异常。
执行此操作的正确语法是什么?谢谢。
【问题讨论】:
标签: python django unit-testing mocking