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

consider a story file as testfile if in test directory #7483

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions changelog/7483.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When using `rasa test` or `rasa test core`, story files in the `tests` directory
are automatically considered as test files. If files in other directories should be
considered as well, prefix them with `test_`.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
TEST_STORIES_FILE_PREFIX,
DOCS_URL_RULES,
DOCS_URL_SLOTS,
DEFAULT_E2E_TESTS_PATH,
)

from rasa.shared.core.constants import RULE_SNIPPET_ACTION_NAME
Expand Down Expand Up @@ -180,7 +181,7 @@ def is_key_in_yaml(cls, file_path: Union[Text, Path], *keys: Text) -> bool:
return any(key in content for key in keys)

@classmethod
def _has_test_prefix(cls, file_path: Text) -> bool:
def _has_test_prefix(cls, file_path: Union[Text, Path]) -> bool:
"""Check if the filename of a file at a path has a certain prefix.

Arguments:
Expand All @@ -202,7 +203,13 @@ def is_test_stories_file(cls, file_path: Union[Text, Path]) -> bool:
`True` if it's a conversation test file, otherwise `False`.
"""

return cls._has_test_prefix(file_path) and cls.is_stories_file(file_path)
in_test_directory = any(
parent.name == DEFAULT_E2E_TESTS_PATH
for parent in Path(file_path).absolute().parents
)
return (
cls._has_test_prefix(file_path) or in_test_directory
) and cls.is_stories_file(file_path)

def get_steps(self) -> List[StoryStep]:
self._add_current_stories_to_result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

from rasa.shared.exceptions import FileNotFoundException, YamlSyntaxException
import rasa.shared.utils.io
from rasa.shared.constants import LATEST_TRAINING_DATA_FORMAT_VERSION
from rasa.shared.constants import (
LATEST_TRAINING_DATA_FORMAT_VERSION,
DEFAULT_E2E_TESTS_PATH,
)
from rasa.core import training
from rasa.shared.core.constants import RULE_SNIPPET_ACTION_NAME
from rasa.shared.core.domain import Domain
Expand Down Expand Up @@ -400,6 +403,14 @@ def test_is_test_story_file(tmp_path: Path):
assert YAMLStoryReader.is_test_stories_file(path)


def test_is_test_story_file_if_in_test_directory(tmp_path: Path):
parent_dir = tmp_path / DEFAULT_E2E_TESTS_PATH
parent_dir.mkdir()
path = parent_dir / "test_stories.yml"
rasa.shared.utils.io.write_yaml({"stories": []}, path)
assert YAMLStoryReader.is_test_stories_file(path)


def test_is_not_test_story_file_if_it_doesnt_contain_stories(tmp_path: Path):
path = str(tmp_path / "test_stories.yml")
rasa.shared.utils.io.write_yaml({"nlu": []}, path)
Expand Down