Assume I have a step defined as follows:
Then I would expect to see the following distribution for Ford
| engine | doors | color |
| 2.1L | 4 | red |
And I have the step implementation that reads the table and does the assert as follows:
@then('I would expect to see the following distribution for {car_type}')
def step(context, car_type):
car = find_car_method(car_type)
for row in context.table:
for heading in row.headings:
assertEqual(getattr(car, heading),
row[heading],
"%s does not match. " % heading + \
"Found %s" % getattr(car, heading))
(I do it like this as this approach allows for adding more fields, but keeping it generic enough for many uses of checking attributes of the car).
When my car object has 4 doors (as an int), it does not match as data table requires that there are '4' doors (as a unicode str).
I could implement this method to check the name of the column and handle it differently for different fields, but then maintenance becomes harder when adding a new field as there is one more place to add it. I would prefer specifying it in the step data table instead. Something like:
Then I would expect to see the following distribution for Ford
| engine | doors:int | color |
| 2.1L | 4 | red |
Is there something similar that I can use to achieve this (as this does not work)?
Note that I have cases where I need to create from the data table where I have the same problem. This make is useless trying to use the type of the 'car' object to determine the type as it is None in that case.
Thank you,
Baire