diff --git a/src/nl2gherkin/exporters/pytest_bdd.py b/src/nl2gherkin/exporters/pytest_bdd.py index 9c8cb74..0aa670e 100644 --- a/src/nl2gherkin/exporters/pytest_bdd.py +++ b/src/nl2gherkin/exporters/pytest_bdd.py @@ -1,7 +1,5 @@ """pytest-bdd exporter for pytest projects.""" -from typing import Dict, List - from nl2gherkin.exporters.base import BaseExporter @@ -12,12 +10,12 @@ class PytestBDDExporter(BaseExporter): """Initialize the pytest-bdd exporter.""" pass - def export(self, features: List[str]) -> str: + def export(self, features: list[str]) -> str: """Export features to pytest-bdd format. - + Args: features: List of Gherkin feature strings. - + Returns: pytest-bdd-compatible feature file content. """ @@ -26,7 +24,7 @@ class PytestBDDExporter(BaseExporter): def get_step_definitions_template(self) -> str: """Get pytest-bdd step definitions template. - + Returns: Step definitions template string. """ @@ -57,9 +55,9 @@ def expected_result(): pass ''' - def get_configuration_template(self) -> Dict[str, str]: + def get_configuration_template(self) -> dict[str, str]: """Get pytest-bdd configuration files. - + Returns: Dictionary mapping filenames to content. """ @@ -83,18 +81,20 @@ def pytest_configure(config): """Configure pytest.""" pass ''', - "pytest.ini": '''[pytest] + "pytest.ini": """[pytest] bdd_features_base_dir = features/ -''', +""", } - def generate_step_definitions(self, scenarios: List[str], feature_name: str = "features") -> str: + def generate_step_definitions( + self, scenarios: list[str], feature_name: str = "features" + ) -> str: """Generate step definitions for given scenarios. - + Args: scenarios: List of scenario texts. feature_name: Name of the feature file. - + Returns: Step definitions Python code. """ @@ -116,10 +116,10 @@ bdd_features_base_dir = features/ step_def = stripped.split()[0].lower() params = self._extract_parameters(step_text) - param_str = ", ".join(f'"{p}"' for p in params) if params else "" + ", ".join(f'"{p}"' for p in params) if params else "" if params: - step_impl = f'''@pytest.{step_def}("{step_text}") + step_impl = f'''@{step_def}("{step_text}") def {step_def}_{scenario_name}({", ".join(params)}): """{stripped.split()[0]} step implementation.""" pass @@ -135,7 +135,8 @@ def {step_def}_{scenario_name}(): return "\n".join(step_defs) - def _extract_parameters(self, step_text: str) -> List[str]: + def _extract_parameters(self, step_text: str) -> list[str]: """Extract parameters from a step text.""" import re + return re.findall(r"<([^>]+)>", step_text)