コード例 #1
0
ファイル: test_agent.py プロジェクト: bmedx/prefect
def test_agent_logs_flow_run_exceptions(monkeypatch, runner_token):
    gql_return = MagicMock(return_value=MagicMock(data=MagicMock(
        writeRunLog=MagicMock(success=True))))
    client = MagicMock()
    client.return_value.write_run_log = gql_return
    monkeypatch.setattr("prefect.agent.agent.Client",
                        MagicMock(return_value=client))

    agent = Agent()
    agent._log_flow_run_exceptions(
        flow_runs=[
            GraphQLResult({
                "id":
                "id",
                "serialized_state":
                Scheduled().serialize(),
                "version":
                1,
                "task_runs": [
                    GraphQLResult({
                        "id": "id",
                        "version": 1,
                        "serialized_state": Scheduled().serialize(),
                    })
                ],
            })
        ],
        exc=ValueError("Error Here"),
    )

    assert client.write_run_log.called
    client.write_run_log.assert_called_with(flow_run_id="id",
                                            level="ERROR",
                                            message="Error Here",
                                            name="agent")
コード例 #2
0
def test_agent_logs_flow_run_exceptions_no_flow_runs(monkeypatch, runner_token):
    gql_return = MagicMock(
        return_value=MagicMock(data=MagicMock(writeRunLog=MagicMock(success=True)))
    )
    client = MagicMock()
    client.return_value.write_run_log = gql_return
    monkeypatch.setattr("prefect.agent.agent.Client", MagicMock(return_value=client))

    agent = Agent()
    agent._log_flow_run_exceptions(flow_runs=[], exc=ValueError("Error Here"))

    assert not client.write_run_log.called