Giter Club home page Giter Club logo

Comments (5)

michaelboulton avatar michaelboulton commented on May 24, 2024

I'm guessing this is because it's an integer and user_id is being implicitly converted to an int at some point.

Because it might be desirable to actually have the distinction between an integer and a string being returned I'm not sure what the best thing to do is to fix this - it should at least print something more useful like

Value mismatch: '159295' (type: int) vs '159295' (type: str)

from tavern.

benhowes avatar benhowes commented on May 24, 2024

@michaelboulton This has been released right?

from tavern.

Birne94 avatar Birne94 commented on May 24, 2024

Currently, values from variables can only be passed by using string formatting (user_id: "{user_id}"). This loses any information about the original data type.

We should come up with another way of passing variables as they are. This might also be useful for passing whole json-blocks as data. String-formatting should stay as it has its own use case (e.g. Authorization header formatting).

Maybe a special token might be appropriate here. I am not sure which tokens are reserved in the yaml spec, so the symbol might need to be changed.

user_id: $user_id

from tavern.

michaelboulton avatar michaelboulton commented on May 24, 2024

This can be done using the yaml 'tags' (specs here http://www.yaml.org/spec/1.2/spec.html#id2803311) - for example:

request:
  json:
    user_id: !!int "{user_id_as_int:d}"

and custom tags can also be added (this is used for !include and !uuid).

It should be possible to make this 'pluggable' in future because it is just registering a function (eg

cls.add_constructor('!include', cls.construct_include)
cls.add_constructor('!uuid', makeuuid)
)

from tavern.

Birne94 avatar Birne94 commented on May 24, 2024

Using the default yaml tags does not work, unfortunately, because they are constructed before any string formatting is done.

I propose a solution involving an intermediate token which gets converted after string formatting is done. See #50 for my approach.

from tavern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.