Skip to content

Commit 478d603

Browse files
refactor(tavern/_core/pytest/file.py): Improve handling of initial YAML document in test file
- The loop variable `i` has been renamed to `document_idx` to better reflect its purpose, which is to track the index of the YAML document being processed. - A comment has been added to explain the implicit behavior when the first YAML document has no "stages" but may have other properties like "name". - The variable `merge_down` is now correctly initialized and used based on the index of the document being processed.
1 parent aa5168e commit 478d603

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tavern/_core/pytest/file.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,15 @@ def collect(self) -> Iterator[YamlItem]:
366366
raise exceptions.BadSchemaError from e
367367

368368
merge_down = None
369-
for i, test_spec in enumerate(all_tests):
369+
# Iterate over yaml documents and tests
370+
for document_idx, test_spec in enumerate(all_tests):
370371
if not test_spec:
371372
logger.warning("Empty document in input file '%s'", self.path)
372373
continue
373374

374-
if i == 0 and not test_spec.get("stages"):
375+
if document_idx == 0 and not test_spec.get("stages"):
376+
# If it's the first document and there were no tests, its implicitly the
377+
# 'defaults' for the file and will be merged with all lower documents
375378
if test_spec.get("name"):
376379
logger.warning("initial block had no stages, but had a name")
377380
merge_down = test_spec

0 commit comments

Comments
 (0)