Skip to content

Commit

Permalink
Better error message for disorganized functional tests, with all the …
Browse files Browse the repository at this point in the history
…violations
  • Loading branch information
Pierre-Sassoulas committed Mar 23, 2023
1 parent 2ff9a53 commit e42d9e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 16 additions & 6 deletions pylint/testutils/functional/find_functional_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,27 @@ def _check_functional_tests_structure(directory: Path) -> None:
f"{directory} contains too many functional tests files "
+ f"({len(files)} > {REASONABLY_DISPLAYABLE_VERTICALLY})."
)

directory_does_not_exists: list[tuple[Path, Path]] = []
misplaced_file: list[Path] = []
for file in files:
possible_dir = file.parent / file.stem.split("_")[0]
assert not possible_dir.exists(), f"{file} should go in {possible_dir}."

if possible_dir.exists():
directory_does_not_exists.append((file, possible_dir))
# Exclude some directories as they follow a different structure
if (
not len(file.parent.stem) == 1 # First letter sub-directories
and file.parent.stem not in IGNORED_PARENT_DIRS
and file.parent.parent.stem not in IGNORED_PARENT_PARENT_DIRS
):
assert file.stem.startswith(
file.parent.stem
), f"{file} should not go in {file.parent}"
if not file.stem.startswith(file.parent.stem):
misplaced_file.append(file)
if directory_does_not_exists or misplaced_file:
msg = "The following functional tests are disorganized:\n"
for file, possible_dir in directory_does_not_exists:
msg += f"- {file} should go in {possible_dir}\n"
for file in misplaced_file:
msg += (
f"- {file} should go in a directory that starts with the first letters"
f" of '{file.stem}' (not '{file.parent.stem}')\n"
)
raise AssertionError(msg)
6 changes: 5 additions & 1 deletion tests/testutils/test_functional_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def test_parsing_of_pylintrc_init_hook() -> None:

def test_get_functional_test_files_from_directory() -> None:
"""Test that we correctly check the functional test directory structures."""
with pytest.raises(AssertionError, match="using_dir.py should not go in"):
match = (
"using_dir.py should go in a directory that starts with the "
"first letters of 'using_dir'"
)
with pytest.raises(AssertionError, match=match):
get_functional_test_files_from_directory(DATA_DIRECTORY)


Expand Down

0 comments on commit e42d9e5

Please sign in to comment.