def from_file(cls, file_): """ Construct a test class from a feature file. """ feature = TestFeature.from_file(file_) background = cls.make_background(feature.background) scenarios = [ cls.make_scenario(scenario, i + 1) for i, scenario in enumerate(feature.scenarios) ] before_feature, after_feature = \ CALLBACK_REGISTRY.before_after('feature') members = { 'feature': feature, 'background': background, 'before_feature': staticmethod(before_feature), 'after_feature': staticmethod(after_feature), } members.update({ scenario.__name__: scenario for scenario in scenarios }) class_name = identifier(feature.name) testclass = type(class_name, (cls,), members) testclass.feature.testclass = testclass return testclass
def from_file(cls, file_): """ Construct a test class from a feature file. """ feature = TestFeature.from_file(file_) background = cls.make_background(feature.background) scenarios = [ example for i, scenario in enumerate(feature.scenarios) for example in cls.make_examples(scenario, i + 1) ] before_feature, after_feature = \ CALLBACK_REGISTRY.before_after('feature') members = { 'feature': feature, 'background': background, 'before_feature': staticmethod(before_feature), 'after_feature': staticmethod(after_feature), } members.update({scenario.__name__: scenario for scenario in scenarios}) class_name = identifier(feature.name) testclass = type(class_name, (cls, ), members) testclass.feature.testclass = testclass return testclass
def from_file(cls, file_): """ Construct a test class from a feature file. """ feature = Feature.from_file( file_, parser_class=TestGherkin, ) background = cls.make_background(feature.background) scenarios = [ cls.make_scenario(scenario, i + 1) for i, scenario in enumerate(feature.scenarios) ] before_feature, after_feature = \ CALLBACK_REGISTRY.before_after('feature') members = { 'feature': feature, 'background': background, 'before_feature': staticmethod(before_feature), 'after_feature': staticmethod(after_feature), } members.update({scenario.__name__: scenario for scenario in scenarios}) class_name = always_str(feature.name) return type(class_name, (cls, ), members)
def session_hooks(): before_all, after_all = CALLBACK_REGISTRY.before_after("all") # setup_stuff before_all() yield # teardown_stuff after_all()
def ensure_before_callbacks(self): """ Before the first test, run the "before all" callbacks. """ if not hasattr(self, 'after_hook'): before_all, after_all = CALLBACK_REGISTRY.before_after('all') before_all() self.after_hook = after_all