Search code examples
pythonbddpython-behave

Generate data for behave tables in runtime


I have a behave test where I would like to have part of the data inside a behave table to be generated after a step has executed. E.g.

Given I have a step
When I executed some other step
Then the message should have the following data
     | field | value |
     | a     | 20    |
     | b     | 30    |
     | var   | <val> |

Once the when step has been executed, I would like to modify <val> to some value depending on that step.


Solution

  • Probably you can combine these two steps together and in that step:

    1. do what you do for your 'when' step
    2. do a context.execute_steps with parameters, for example:

    context.execute_steps(u'''Then doing something with "you_parameters"'''.format(you_parameter=value)

    And of course you can do context.execute_steps with a table having the data you generated