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

Ability to write variables in test file #748

Open
ashishpatel1992 opened this issue Dec 14, 2021 · 5 comments
Open

Ability to write variables in test file #748

ashishpatel1992 opened this issue Dec 14, 2021 · 5 comments

Comments

@ashishpatel1992
Copy link

Looking forward for something like
where users are able to declare their own variables inside tavern file. I know there is a way to use !include and declare but I want it to be specific to this test case file.

test_name: Sample Test Name
variables:
  common_url: "https://sample.com/{group_endpoint}"

stages:
  - name: List specific group with id
    request:
        url: "{common_url}/id/abc1"
        method: GET
    response:
        status_code: 200

  - name: List specific group with id2
    request:
        url: "{common_url}/id/abc2"
        method: GET
    response:
        status_code: 200

@michaelboulton
Copy link
Member

You can do something like by doing

test_name: test name

includes:
  - name: variables
    description: variables
    variables:
      a: b

but it's not very nice. I may just remove the need to put the 'name' and 'description' fields in a configuration file (or at least the description) as this is often not needed

@ashishpatel1992
Copy link
Author

Umm.. Looks good solution but the only thing that makes me worried is I have common.yaml included in pytest.ini file, I am not able to use variables from it in local variables.

Example: I have global domain_name, port variables in common.yaml
Now I want to build url in local variable

test_name: test name

includes:
  - name: variables
    description: variables
    variables:
      list_all_users: "https://{domain_name}:{port}/users/"
      select_user: "https://{domain_name}:{port}/users/55"

Now I want to use list_all_users at multiple places

@michaelboulton
Copy link
Member

Ah sorry, I didn't realise you meant inside one file and not just in one test.

Each test in Tavern is a separate YAML document and are all basically treated as separate files so you can't do something like that. Do you want something like:

variables:
      list_all_users: "https://{domain_name}:{port}/users/"
      select_user: "https://{domain_name}:{port}/users/55"
---
test_name: test 1
stages:
	...
---
test_name: test 2
stages:
	...

?

@jaywon
Copy link

jaywon commented Jan 10, 2022

@michaelboulton Have similar interest and what you described is the solution I would hope for?

@ashishpatel1992
Copy link
Author

ashishpatel1992 commented Jan 10, 2022

What I mean is I have a common.yaml file which contains some variables like domain name and port number.
But now I want to add more variable specific to the test only and use some variables from common.yaml to build new variables specific for the current test file.

Ah sorry, I didn't realise you meant inside one file and not just in one test.

Each test in Tavern is a separate YAML document and are all basically treated as separate files so you can't do something like that. Do you want something like:

variables:
      list_all_users: "https://{domain_name}:{port}/users/"
      select_user: "https://{domain_name}:{port}/users/55"
---
test_name: test 1
stages:
	...
---
test_name: test 2
stages:
	...

?

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

3 participants