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

[data] Adding in better json checking in test logging #48036

Merged
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
21 changes: 11 additions & 10 deletions python/ray/data/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def test_custom_config(reset_logging, monkeypatch, tmp_path):
def test_json_logging_configuration(
capsys, reset_logging, monkeypatch, shutdown_only, propagate_logs
):
import json

monkeypatch.setenv("RAY_DATA_LOG_ENCODING", "JSON")
ray.init()

Expand All @@ -148,20 +150,19 @@ def test_json_logging_configuration(
log_contents = file.read()

# Validate the log is in JSON format (a basic check for JSON)
assert all(
log_line.startswith("{") and log_line.endswith("}")
for log_line in log_contents.splitlines()
)
messages = []
for log_line in log_contents.splitlines():
log_dict = json.loads(log_line) # will error if not a json line
messages.append(log_dict["message"])

assert '"message": "ham"' in log_contents
assert '"message": "turkey"' in log_contents
assert "ham" in messages
assert "turkey" in messages

# Validate console logs are in text mode
console_log_output = capsys.readouterr().err
assert not any(
log_line.startswith("{") and log_line.endswith("}")
for log_line in console_log_output.splitlines()
)
for log_line in console_log_output.splitlines():
with pytest.raises(json.JSONDecodeError):
json.loads(log_line)

assert "ham" in console_log_output
assert "turkey" not in console_log_output
Expand Down