Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve parser performance #623

Merged
merged 4 commits into from
Jul 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import typing
from collections import OrderedDict
from dataclasses import dataclass, field
from functools import cached_property
from typing import cast

from . import exceptions, types
Expand Down Expand Up @@ -318,9 +319,11 @@ def add_line(self, line: str) -> None:
:param str line: Line of text - the continuation of the step name.
"""
self.lines.append(line)
if "full_name" in self.__dict__:
del self.__dict__["full_name"]

@property
def name(self) -> str:
@cached_property
def full_name(self) -> str:
multilines_content = textwrap.dedent("\n".join(self.lines)) if self.lines else ""

# Remove the multiline quotes, if present.
Expand All @@ -334,9 +337,15 @@ def name(self) -> str:
lines = [self._name] + [multilines_content]
return "\n".join(lines).strip()

@property
def name(self) -> str:
return self.full_name

@name.setter
def name(self, value: str) -> None:
self._name = value
if "full_name" in self.__dict__:
del self.__dict__["full_name"]

def __str__(self) -> str:
"""Full step name including the type."""
Expand Down