CITCOM-project / causcumber

Cucumber driven causal inference for testing computational models.
1 stars 1 forks source link

Clashes in behave decorator (`@given`) #23

Open bobturneruk opened 2 years ago

bobturneruk commented 2 years ago

@given decorators, part of the behave package take a string as a argument. This argument matches a "given" statement in a feature file, and executes the decorated function, typically step_impl on the basis of this.

If the same string is passed to two @given decorators in a single run, it causes an error. We would like for @given decorators in imported modules to be "overriden" by other statements, allowing default behaviour to be changed for specific cases.

Relates to https://github.com/CITCOM-project/causcumber/issues/20 and https://github.com/behave/behave/issues/630

bobturneruk commented 2 years ago

extends to the @when and @then decorators as well

bobturneruk commented 2 years ago

Used vscode debugger to track down definition and execution of decorators via:

from behave.__main__ import main as behave_main
behave_main("./features/")

Definition goes on around here (I think):

https://github.com/behave/behave/blob/9520119376046aeff73804b5f1ea05d87a63f370/behave/step_registry.py#L89

@given, @when and @then decorators are apparently the same apart from their name. I think I need to learn more about how step_impl functions are decorated. This probably means unravelling the sequence of event in punner.py https://github.com/behave/behave/blob/master/behave/runner.py.

I was able to replicate this issue in a simple example with two of these:

@given('we have behave installed')
def step_impl(context):
   ...

in separate files.

jmafoster1 commented 2 years ago

After a meeting with @AndrewC19 it turns out that that this extends beyond just the step definitions to all aspects of the causecumber framework. We will also possibly need to override/extend the (actual) hook methods like before_feature, before_tag, etc. to enable us to do what we need to to get causecumber running while still allowing users to extend and add functionality.