0

Currently I'm writting some integration tests in Python Lettuce. I want to create a generic step for some XML's comparision.

I know that in .feature file after step definition like

Scenario: I want to compare XML's...
 ...
 And I check generated transaction "XYZ" contents with parameters:
 ...

I can add step.hashes, which would be available in step.hashes property in step definition (some_step_definitions.py bellow)

@step(u'And I check generated transaction "([^"]+)" contents with parameters:$')
def check_generated_content(step, transaction_type):
    *(some xml mappings for comparision, appending dictionaries to step.hashes)*
    for item in mappings:
       step.hashes.append({
          'key1': 'val1',
          'key2': 'val2'
       })

My question is: Is it possible to append headers (key1, key2) in step code (check_generated_content), that when tests are executed I have headers in test report like:

Scenario: I want to compare XML's...
 ...
 And I check generated transaction "XYZ" contents with parameters:
| key1 | key2 |
| val1 | val2 |
...

When I dont specify

And I check generated transaction "XYZ" contents with parameters:
| key1 | val1 |

in feature file, I get in test report:

And I check generated transaction "XYZ" contents with parameters:
| | |
| | |

In conclusion.. I would like to write only

And I check generated transaction "XYZ" contents with parameters:

instead of

And I check generated transaction "XYZ" contents with parameters:
| key1 | val1 |

every time.

Kenster
  • 23,465
  • 21
  • 80
  • 106
paulluap
  • 1
  • 1

1 Answers1

0

So in meantime when writting this, I've came up with solution. It was pretty easy... in step code definition what I needed to add were default values for step keys

step.keys = [ 'key1', 'val1' ]

Then I could append hashes to step.hashes. After that I've executed step with behave_as method

step.behave_as(step.sentence + '\n' + step.represent_hashes())

And everything was beautifully printed in test output.

paulluap
  • 1
  • 1