Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hhhieu opened this issue Jul 22, 2023 · 1 comment
Open

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

hhhieu opened this issue Jul 22, 2023 · 1 comment

Comments

@hhhieu
Copy link

hhhieu commented Jul 22, 2023

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
Copy link
Member

glyph commented Jul 23, 2023

Thanks for the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants