0

I like using Lettuce to define test cases. In many cases, it's easy to write Lettuce scenarios in such a way that they can be run either atomically or as part of other scenarios in a feature. However, I find that Lettuce is also a useful tool to try and reason about and implement more complex integration tests. In these cases, it makes sense to break up the tests into scenarios, but define a dependency on a previous scenario. That way I can run a scenario without having to explicitly define which other scenarios need to be run. It also makes the dependency clear in the scenario definition. This might look something like this:

Scenario: Really long scenario
    Given some condition
    Given another condition
    Then something
    ...

Scenario: A dependent scenario
    Given the scenario "Really long scenario" has been run
    Given new condition
    Then some stuff
    ...

Then I could do something like:

@step('Given the scenario "([^"]*)" has been run')
def check_scenario(step, sentence):
    scenario = get_scenario(sentence) # This what I don't know how to do
    if not scenario.ran:
        scenario.run()

How do you handle this situation? Are there any gotchas I'm missing with this approach? Taking a quick look through the API docs and the source code, it didn't seem like there was an easy way to retrieve a scenario by it's string.

Geoffrey Hing
  • 1,575
  • 2
  • 15
  • 22

2 Answers2

1

The only thing I know about is defining new steps which call previously defined steps: Check out the tutorial about that topic. Maybe this can be a good workaround for your problem.

Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
0

You can use world in order to store data between your scenarios.

@before.each_feature
def feature_setup(feature):
    ...
    world.feature_data = dict()
    ...

You can access this data from everywhere you have access to world

You can mix it with your terrain.py file in order to save data between steps, scenarios, features.

PukeCloud
  • 116
  • 8
  • Thanks for this mention. I'm aware of this capability. I was asking how to implement dependencies between scenarios both in the definition and the implementation. I think @Torsten's suggestion below gets closer to this. – Geoffrey Hing Jul 22 '13 at 16:29