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

Question about external function kwargs in requests #860

Open
Syuparn opened this issue Apr 14, 2023 · 1 comment
Open

Question about external function kwargs in requests #860

Syuparn opened this issue Apr 14, 2023 · 1 comment
Labels
Requires Documentation Documentation needs adding for this PR or to solve this issue

Comments

@Syuparn
Copy link

Syuparn commented Apr 14, 2023

The document says external functions used in a request block should not take arguments.

https://tavern.readthedocs.io/en/latest/basics.html?highlight=external%20function#using-external-functions-for-other-things

Functions used in the verify_response_with block in the response block take the response as the first argument. Functions used anywhere else should take no arguments. This might be changed in future to be less confusing.

On the other hand, extra_kwargs in the request block works as expected and the same as in the response block.

  • Version: Tavern 2.0.6
  - name: send a dummy header
    request:
      url: http://httpbin.org/headers
      method: GET
      headers:
        $ext:
          function: utils:generate_message
          extra_kwargs: # kwargs can be used!
            person: Mike
from box import Box


def generate_message(person: "John"):
    headers = {
        "Dummy-Person-Header": person
    }
    return Box(headers)

(Full contents are in https://gist.github.com/Syuparn/34e26705e67a2240c1a2abfa119d8554)

Is this an expected use? Which does This might be changed in future to be less confusing. mean,

  1. functions in the request could not handle arguments in the older version, while in 2.0.6 they can
    or
  2. In 2.0.6 functions can handle arguments but this is deprecated and the feature will be removed
    ?
@michaelboulton michaelboulton added the Requires Documentation Documentation needs adding for this PR or to solve this issue label Apr 15, 2023
@michaelboulton
Copy link
Member

This is just bad wording in the documentation, it basically just means that if your function expects extra args it won't work unless you explicitly put the arguments in extra_args or extra_kwargs. Will fix the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Requires Documentation Documentation needs adding for this PR or to solve this issue
Projects
None yet
Development

No branches or pull requests

2 participants