Skip to content

Commit

Permalink
tests: save approved files to new directory
Browse files Browse the repository at this point in the history
New directories names are based on the test file names.

PytestNamer class for managing approval test file paths got updated
accordingly.
  • Loading branch information
matthiasschaub committed Nov 13, 2024
1 parent fdd4059 commit 9847136
Show file tree
Hide file tree
Showing 123 changed files with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/namer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ def __init__(self, extension=None):
consist of the nodeid and the current stage:
`relative/path/to/test_file.py::TestClass::test_func[a] (call)`
"""
# pytest node ID w/out directories
self.nodeid = os.environ["PYTEST_CURRENT_TEST"].split("/")[-1]
NamerBase.__init__(self, extension)

def get_file_name(self) -> str:
# TODO: name clashes are possible.
# Include dir names (except tests/integration/) to avoid name clashes
nodeid = os.environ["PYTEST_CURRENT_TEST"]
nodeid_without_dir = nodeid.split("/")[-1]
return nodeid_without_dir.replace(" (call)", "")
"""File name is pytest nodeid w/out file name and ` (call)` postfix."""
return self.nodeid.split("::")[1].replace(" (call)", "")

def get_directory(self) -> Path:
return APPROVED_DIR
"""Directory is `tests/fixtures/approval/{file_name}/`."""
# TODO: name clashes are possible.
# Include dir names (except tests/integration/) to avoid name clashes
return APPROVED_DIR / self.nodeid.split("::")[0].replace(".py", "")

def get_config(self) -> dict:
return {}
Expand Down

0 comments on commit 9847136

Please sign in to comment.