6
6
import typing
7
7
from collections import OrderedDict
8
8
from dataclasses import dataclass , field
9
+ from functools import cached_property
9
10
from typing import cast
10
11
11
12
from . import exceptions , types
@@ -292,7 +293,6 @@ class Scenario:
292
293
class Step :
293
294
type : str
294
295
_name : str
295
- _full_name : str | None
296
296
line_number : int
297
297
indent : int
298
298
keyword : str
@@ -312,37 +312,40 @@ def __init__(self, name: str, type: str, indent: int, line_number: int, keyword:
312
312
self .scenario = None
313
313
self .background = None
314
314
self .lines = []
315
- self ._full_name = None
316
315
317
316
def add_line (self , line : str ) -> None :
318
317
"""Add line to the multiple step.
319
318
320
319
:param str line: Line of text - the continuation of the step name.
321
320
"""
322
321
self .lines .append (line )
323
- self ._full_name = None
322
+ if "full_name" in self .__dict__ :
323
+ del self .__dict__ ["full_name" ]
324
+
325
+ @cached_property
326
+ def full_name (self ) -> str :
327
+ multilines_content = textwrap .dedent ("\n " .join (self .lines )) if self .lines else ""
328
+
329
+ # Remove the multiline quotes, if present.
330
+ multilines_content = re .sub (
331
+ pattern = r'^"""\n(?P<content>.*)\n"""$' ,
332
+ repl = r"\g<content>" ,
333
+ string = multilines_content ,
334
+ flags = re .DOTALL , # Needed to make the "." match also new lines
335
+ )
336
+
337
+ lines = [self ._name ] + [multilines_content ]
338
+ return "\n " .join (lines ).strip ()
324
339
325
340
@property
326
341
def name (self ) -> str :
327
- if self ._full_name is None :
328
- multilines_content = textwrap .dedent ("\n " .join (self .lines )) if self .lines else ""
329
-
330
- # Remove the multiline quotes, if present.
331
- multilines_content = re .sub (
332
- pattern = r'^"""\n(?P<content>.*)\n"""$' ,
333
- repl = r"\g<content>" ,
334
- string = multilines_content ,
335
- flags = re .DOTALL , # Needed to make the "." match also new lines
336
- )
337
-
338
- lines = [self ._name ] + [multilines_content ]
339
- self ._full_name = "\n " .join (lines ).strip ()
340
- return self ._full_name
342
+ return self .full_name
341
343
342
344
@name .setter
343
345
def name (self , value : str ) -> None :
344
346
self ._name = value
345
- self ._full_name = None
347
+ if "full_name" in self .__dict__ :
348
+ del self .__dict__ ["full_name" ]
346
349
347
350
def __str__ (self ) -> str :
348
351
"""Full step name including the type."""
0 commit comments