MCPcopy Create free account
hub / github.com/pytest-dev/pytest-bdd / render_string

Function render_string

src/pytest_bdd/parser.py:27–45  ·  view source on GitHub ↗

Render the string with the given context, but avoid replacing text inside angle brackets if context is missing. Args: input_string (str): The string for which to render/replace params. render_context (Mapping[str, object]): The context for rendering the string. Ret

(input_string: str, render_context: Mapping[str, object])

Source from the content-addressed store, hash-verified

25
26
27def render_string(input_string: str, render_context: Mapping[str, object]) -> str:
28 """
29 Render the string with the given context,
30 but avoid replacing text inside angle brackets if context is missing.
31
32 Args:
33 input_string (str): The string for which to render/replace params.
34 render_context (Mapping[str, object]): The context for rendering the string.
35
36 Returns:
37 str: The rendered string with parameters replaced only if they exist in the context.
38 """
39
40 def replacer(m: re.Match) -> str:
41 varname = m.group(1)
42 # If the context contains the variable, replace it. Otherwise, leave it unchanged.
43 return str(render_context.get(varname, f"<{varname}>"))
44
45 return PARAM_RE.sub(replacer, input_string)
46
47
48def get_tag_names(tag_data: list[GherkinTag]) -> set[str]:

Callers 2

renderMethod · 0.85
render_datatableMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…