twisted / treq

Python requests like API built on top of Twisted's HTTP client.
Other
585 stars 137 forks source link

StubTreq doesn't handle the 'persistent' key argument #372

Open hhhieu opened 1 year ago

hhhieu commented 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

glyph commented 1 year ago

Thanks for the bug report.