|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import copy |
3 | 4 | import os.path
|
4 | 5 | import re
|
5 | 6 | import textwrap
|
@@ -218,7 +219,7 @@ def render(self, context: Mapping[str, Any]) -> Scenario:
|
218 | 219 | indent=step.indent,
|
219 | 220 | line_number=step.line_number,
|
220 | 221 | keyword=step.keyword,
|
221 |
| - datatable=step.render_datatable(context), |
| 222 | + datatable=step.render_datatable(step.datatable, context) if step.datatable else None, |
222 | 223 | docstring=render_string(step.docstring, context) if step.docstring else None,
|
223 | 224 | )
|
224 | 225 | for step in base_steps
|
@@ -329,24 +330,24 @@ def params(self) -> tuple[str, ...]:
|
329 | 330 | """
|
330 | 331 | return tuple(frozenset(STEP_PARAM_RE.findall(self.name)))
|
331 | 332 |
|
332 |
| - def render_datatable(self, context: Mapping[str, Any]) -> DataTable | None: |
| 333 | + @staticmethod |
| 334 | + def render_datatable(datatable: DataTable, context: Mapping[str, object]) -> DataTable: |
333 | 335 | """
|
334 | 336 | Render the datatable with the given context,
|
335 | 337 | but avoid replacing text inside angle brackets if context is missing.
|
336 | 338 |
|
337 | 339 | Args:
|
| 340 | + datatable (DataTable): The datatable to render. |
338 | 341 | context (Mapping[str, Any]): The context for rendering the datatable.
|
339 | 342 |
|
340 | 343 | Returns:
|
341 | 344 | datatable (DataTable): The rendered datatable with parameters replaced only if they exist in the context.
|
342 | 345 | """
|
343 |
| - if self.datatable: |
344 |
| - rendered_datatable = self.datatable |
345 |
| - for row in rendered_datatable.rows: |
346 |
| - for cell in row.cells: |
347 |
| - cell.value = render_string(cell.value, context) |
348 |
| - return rendered_datatable |
349 |
| - return None |
| 346 | + rendered_datatable = copy.deepcopy(datatable) |
| 347 | + for row in rendered_datatable.rows: |
| 348 | + for cell in row.cells: |
| 349 | + cell.value = render_string(cell.value, context) |
| 350 | + return rendered_datatable |
350 | 351 |
|
351 | 352 |
|
352 | 353 | @dataclass(eq=False)
|
|
0 commit comments