I am running multiple scenarios and would like to incorporate some sort of dynamic scenario dispatcher which would allow me to have specific steps to execute after a test is done based on the scenario executed. When I was using PHPUnit, I used to be able to subclass the TestCase class and add my own setup and teardown methods. For behave, what I have been doing is adding an extra "Then" step at the end of the scenario which would be executed once the scenario finishes to clean up everything - clean up the configuration changes made by scenario, etc. But since every scenario is different, the configuration changes I need to make are specific to a scenario so I can't use the after_scenario hook that I have in my environment.py file. Any ideas on how to implement something similar?
What I've been doing might give you an idea:
In the before_all specify a list in the context (eg context.teardown_items =[]).
Then in the various steps of various scenarios add to that list (accounts, orders or whatever)
Then in the after_all I login as a superuser and clean everything up I specified in that list.
Could something like that work for you ?
Dynamic scenario dispatcher for Python Behave