TypeError: quote_from_bytes() expected bytes on mocker.spy
jramosss opened this issue · 1 comments
jramosss commented
When i'm trying to mock a stripe function, i get the following trace.
resources/payments/tests/test_webhooks.py:122: in test_subscription_updated_trial
stripe_client.handle_events(stripe_events.CUSTOMER_SUBSCRIPTION_UPDATED, event_data)
resources/payments/stripe.py:290: in handle_events
self.handle_subscription_updated(event_data)
resources/payments/stripe.py:119: in handle_subscription_updated
stripe.Subscription.delete(workspace.stripe_subscription)
<string>:3: in delete
???
/usr/lib/python3.8/unittest/mock.py:1081: in __call__
return self._mock_call(*args, **kwargs)
/usr/lib/python3.8/unittest/mock.py:1085: in _mock_call
return self._execute_mock_call(*args, **kwargs)
/usr/lib/python3.8/unittest/mock.py:1146: in _execute_mock_call
result = effect(*args, **kwargs)
/home/chuls/.virtualenvs/workspaces/lib/python3.8/site-packages/pytest_mock/plugin.py:124: in wrapper
r = method(*args, **kwargs)
/home/chuls/.virtualenvs/workspaces/lib/python3.8/site-packages/stripe/util.py:267: in _wrapper
return class_method(*args, **kwargs)
/home/chuls/.virtualenvs/workspaces/lib/python3.8/site-packages/stripe/api_resources/abstract/deletable_api_resource.py:11: in _cls_delete
url = "%s/%s" % (cls.class_url(), quote_plus(util.utf8(sid)))
/usr/lib/python3.8/urllib/parse.py:877: in quote_plus
string = quote(string, safe + space, encoding, errors)
/usr/lib/python3.8/urllib/parse.py:861: in quote
return quote_from_bytes(string, safe)
/usr/lib/python3.8/urllib/parse.py:886: in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
E TypeError: quote_from_bytes() expected bytes
This is the way i call it
spy = mocker.spy(stripe.Subscription, "delete")
This are my libraries versions:
python3.8
pytest 7.1.3
pytest-benchmark 3.4.1
pytest-cov 3.0.0
pytest-django 4.5.2
pytest-lazy-fixture 0.6.3
pytest-mock 3.8.2
pytest-sugar 0.9.5
pytest-xdist 3.0.2
nicoddemus commented
Note you are not mocking it, you are using mocker.spy
, which still calls the original function. Did you mean to use mocker.patch.object
instead?