Skip to content

Commit

Permalink
Ignored empty and blank lines in replay file
Browse files Browse the repository at this point in the history
Fixes #70

Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
  • Loading branch information
DavideCanton and nicoddemus authored Nov 29, 2024
1 parent 0824957 commit 80089a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UNRELEASED
==========

* Ignore empty and blank lines in the replay file (`#70`_).

.. _`#70`: https://github.com/ESSS/pytest-replay/issues/70

1.5.2 (2024-09-03)
==================

Expand Down
12 changes: 7 additions & 5 deletions src/pytest_replay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ def pytest_collection_modifyitems(self, items, config):
with open(replay_file, encoding="UTF-8") as f:
all_lines = f.readlines()
# Use a dict to deduplicate the node ids while keeping the order.
nodeids = dict.fromkeys(
json.loads(line)["nodeid"]
for line in all_lines
if not line.strip().startswith(("#", "//"))
)
nodeids = {}
for line in all_lines:
stripped = line.strip()
# Ignore blank linkes and comments. (#70)
if stripped and not stripped.startswith(("#", "//")):
nodeid = json.loads(stripped)["nodeid"]
nodeids[nodeid] = None

items_dict = {item.nodeid: item for item in items}
remaining = []
Expand Down
28 changes: 28 additions & 0 deletions tests/test_replay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools as it
import json
import re
from pathlib import Path

import pytest

Expand Down Expand Up @@ -403,3 +404,30 @@ def test_test_fail_skip_teardown(skip_teardown):
"test_module.py::test_skip_teardown": "skipped",
"test_module.py::test_test_fail_skip_teardown": "failed",
}


@pytest.mark.usefixtures("suite")
def test_empty_or_blank_lines(testdir):
"""Empty or blank line in replay files should be ignored."""
dir = testdir.tmpdir / "replay"
options = [f"--replay-record-dir={dir}"]
result = testdir.runpytest(*options)

replay_file: Path = dir / ".pytest-replay.txt"

with replay_file.open("r+") as f:
content = f.readlines()

# Add empty line
content.insert(1, "\n")
# Add blank line
content.insert(1, " \n")
# Add empty line
content.append("\n")
# Add mixed blank line
content.append("\t \n")
f.seek(0)
f.writelines(content)

result = testdir.runpytest(f"--replay={replay_file}", "-v")
assert result.ret == 0

0 comments on commit 80089a3

Please sign in to comment.