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

Pass a parameter to stage #776

Open
thejuliakors opened this issue Apr 25, 2022 · 3 comments
Open

Pass a parameter to stage #776

thejuliakors opened this issue Apr 25, 2022 · 3 comments

Comments

@thejuliakors
Copy link

It would be cool to have an opportunity to pass a parameter to the stage. It's possible to do this via parametrize mark, however, there can be cases when we want to pass the parameter we received and saved during previous stages.

I.e. we create two entities (in different ways / with different test data and in different stages) and then we want to delete them and pass the ID of each entity to the delete-stage. In order to do that we should write two very similar stages instead of one and passing first_entity_id/second_entity_id to there.

- id: create_first_entity
   ...
   save:
        json:
          first_entity_id: id

- id: create_second_entity
   ...
   save:
        json:
          second_entity_id: id

- id: delete_first_entity
    name: delete the first smth
    request:
      url: "{tavern.env_vars.API_URL}/v1/admin/smth/{first_entity_id}"
      method: DELETE
      headers: *headers
    response:
      status_code: 204

  - id: delete_second_entity
    name: delete the second smth
    request:
      url: "{tavern.env_vars.API_URL}/v1/admin/smth/{second_entity_id}"
      method: DELETE
      headers: *headers
    response:
      status_code: 204

Maybe, there is some way to do that?
If not, it would be a nice enhancement.

@gc-ss
Copy link

gc-ss commented Apr 26, 2022

Could you make this work with parameterized fixtures?

@thejuliakors
Copy link
Author

Could you make this work with parameterized fixtures?

As far as I know, I can't pass parameters, which I receive in the middle of the test, to the fixture. Of course, I can pass the whole flow to the fixture, write the functions with the parameters I need, and reuse them from this fixture. Or copy-paste as many stages as is needed (like in the example above delete_first_entity/delete_second_entity). For sure there are ways to achieve what I need, however, I'm looking for a nicer one :)

@michaelboulton
Copy link
Member

If you're implying you want to be able to dynamically create stages from parametrised input, that isn't really likely to ever happen because there are a few places where Tavern depends on knowing what is on the source line of the stage.

Personal opinion, but it also makes it a bit confusing where each stage could be expanded to multiple stages depending on user input, so what you're seeing in the file isn't showing the full picture of what stages would actually be run

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