svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 325 forks source link

Global Static Random Values for all test cases #200

Open PKiman opened 8 years ago

PKiman commented 8 years ago

Thank you for creating this great project. I am investigating a way to create a random email address (autogenerated+1592135@example.com) before executing the test cases. The email must be static for all test cases. However I wasn't able to achieve this, because the random generator creates for each test run a new number instead.

svanoort commented 8 years ago

@PKiman Glad you're finding PyRestTest helpful. If you want to create a random email address once, and reuse it across all tests within the same test set (same file generally), create the generator and do a generator_bind ONCE with that generator ID (in the first test). This will generate a value (using your generator) and bind it to the variable.

The variable will remain usable across all tests in that testset unless you modify its value - note that the context and all variables in them are cleared at the end of each testset (so you can't use imports with this). There's an enhancement planned to add that feature in the future.

I've updated the docs to make this clearer since they didn't explain it well.

I hope that answers your question? Regards, Sam

PKiman commented 8 years ago

Thanks that was helpful. It works fine. The email is re-composed across all test cases. Is there a way to compose the email only once in the variable_binds ?

svanoort commented 8 years ago

@PKiman Yes, you define it as a variable_bind with a single value. Not sure what you're asking here?