Open hhhieu opened 1 year ago
If the 'persistent' argument is used in a request, StubTreq will throw exception "an unexpected keyword argument 'persistent'".
hieu@hieu-VirtualBox:~/workspace/treq$ python3 -m twisted.trial subtreq_issue.TestClientWrapper subtreq_issue TestClientWrapper test_get ... [ERROR] =============================================================================== [ERROR] Traceback (most recent call last): File "/home/hieu/workspace/treq/subtreq_issue.py", line 40, in test_get stub_content = yield ClientWrapper(stub_treq).get(url, persistent=False) File "/home/hieu/.local/lib/python3.8/site-packages/twisted/internet/defer.py", line 1697, in _inlineCallbacks result = context.run(gen.send, result) File "/home/hieu/workspace/treq/subtreq_issue.py", line 15, in get resp = yield self.client.get(url, persistent=persistent) File "/home/hieu/.local/lib/python3.8/site-packages/treq/testing.py", line 219, in wrapper return f(*args, **kwargs) File "/home/hieu/.local/lib/python3.8/site-packages/treq/client.py", line 161, in get return self.request('GET', url, **kwargs) builtins.TypeError: request() got an unexpected keyword argument 'persistent' subtreq_issue.TestClientWrapper.test_get ------------------------------------------------------------------------------- Ran 1 tests in 0.010s FAILED (errors=1)
It's ok if we use treq rather than StubTreq. In the source code of treq, it will pop that argument out before passing argument to the "request" function: https://github.com/twisted/treq/blob/release-22.2.0/src/treq/api.py#L220
def _client(kwargs): agent = kwargs.pop("agent", None) pool = kwargs.pop("pool", None) persistent = kwargs.pop("persistent", None)
However, SubTreq didn't pop that argument so it led to this problem
subtreq_issue.zip
Thanks for the bug report.
If the 'persistent' argument is used in a request, StubTreq will throw exception "an unexpected keyword argument 'persistent'".
It's ok if we use treq rather than StubTreq. In the source code of treq, it will pop that argument out before passing argument to the "request" function: https://github.com/twisted/treq/blob/release-22.2.0/src/treq/api.py#L220
However, SubTreq didn't pop that argument so it led to this problem
subtreq_issue.zip