Skip to content

Commit

Permalink
fix expected n logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zzstoatzz committed Nov 12, 2024
1 parent 66a91c7 commit efc6d1c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/integrations/prefect-shell/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,37 @@ async def test_error(self, method):
@pytest.mark.skipif(sys.version >= "3.12", reason="Fails on Python 3.12")
@pytest.mark.parametrize("method", ["run", "trigger"])
async def test_output(self, prefect_task_runs_caplog, method):
# Set the log level to INFO explicitly
prefect_task_runs_caplog.set_level(logging.INFO)

op = ShellOperation(commands=["echo 'testing\nthe output'", "echo good"])
assert await self.execute(op, method) == ["testing", "the output", "good"]
records = prefect_task_runs_caplog.records
assert len(records) == 3
assert "triggered with 2 commands running" in records[0].message
assert "stream output:\ntesting\nthe output\ngood" in records[1].message
assert "completed with return code 0" in records[2].message

# Filter for only INFO level records
log_messages = [
r.message
for r in prefect_task_runs_caplog.records
if r.levelno >= logging.INFO
]
assert any("triggered with 2 commands running" in m for m in log_messages)
assert any(
"stream output:\ntesting\nthe output\ngood" in m for m in log_messages
)
assert any("completed with return code 0" in m for m in log_messages)

@pytest.mark.parametrize("method", ["run", "trigger"])
async def test_stream_output(self, prefect_task_runs_caplog, method):
# If stream_output is False, there should be output,
# but no logs from the shell process
prefect_task_runs_caplog.set_level(logging.INFO) # Only capture INFO logs

op = ShellOperation(
commands=["echo 'testing\nthe output'", "echo good"], stream_output=False
)
assert await self.execute(op, method) == ["testing", "the output", "good"]
records = prefect_task_runs_caplog.records
records = [
r for r in prefect_task_runs_caplog.records if r.levelno >= logging.INFO
]
assert len(records) == 2
assert "triggered with 2 commands running" in records[0].message
assert "completed with return code 0" in records[1].message
Expand Down

0 comments on commit efc6d1c

Please sign in to comment.