jeudi 3 juin 2021

behave.use_step_matcher | how to smartly or efficiently use it? | good design principle?

I need some guidance on how to smartly or efficiently use behave.use_step_matcher().

A. So I am initializing default matcher for all features as parse by declaring behave.use_step_matcher('parse') after all imports in environment.py file.

B. Now in step files, for some steps, I need to use behave.use_step_matcher('re'). So I mention it before those steps only.

C. Now in environment.py file, in after_step(context, step) hook, I reset to use behave.use_step_matcher('parse') matcher.

My problem is that after any step which changes matcher to 're', other steps that need matcher to be 'parse' do not work.

1 solution I found was to explicitly mention use_step_matcher for all steps.

But https://jenisys.github.io/behave.example/step_matcher/using_matchers.html says that to set default matcher for all features set it in environment.py file, which I have done.

Also I am resetting matcher back to parse in after_step hook in environment.py file.

  1. So why it does not work?

  2. Can u help me understand it better?

Also, in future I plan to implement steps library and call behave steps within a behave step (a step calling a step). And in this scenario if parent step uses 'matcher1' but nested steps use different matchers (considering we can create custom matchers).

  1. Then what are the best practices to manage matchers?

It would be very kind if you could guide me through this.

Thanking you!

PS:

  1. I am very naïve with behave & python, I have read https://github.com/behave/behave/issues/613 but did not understand anything. :(

Aucun commentaire:

Enregistrer un commentaire