示例#1
0
def test_on_failure_crashes_gracefully(caplog):
    dag = DAG(name='dag')
    PythonCallable(failing_root, File('file.txt'), dag, name='t')
    dag.on_failure = early_stop

    with caplog.at_level(logging.ERROR):
        out = dag.build()

    assert out is None is None
    assert 'Exception when running on_failure for DAG "dag"' in caplog.text
示例#2
0
def test_on_failure(caplog):
    hook.count = 0

    dag = DAG(name='dag')
    PythonCallable(failing_root, File('file.txt'), dag, name='t')
    dag.on_failure = hook

    with pytest.raises(DAGBuildError):
        dag.build()

    assert hook.count == 1
示例#3
0
def test_on_failure_crashes(caplog):
    hook_crashing.count = 0

    dag = DAG(name='dag')
    PythonCallable(failing_root, File('file.txt'), dag, name='t')
    dag.on_failure = hook_crashing

    with pytest.raises(DAGBuildError):
        with caplog.at_level(logging.ERROR):
            dag.build()

    assert hook_crashing.count == 1
    assert 'Exception when running on_failure for DAG "dag"' in caplog.text
示例#4
0
def test_on_failure_crashes(caplog):
    hook_crashing.count = 0

    dag = DAG(name='dag')
    PythonCallable(failing_root, File('file.txt'), dag, name='t')
    dag.on_failure = hook_crashing

    with pytest.raises(DAGBuildError) as excinfo:
        with caplog.at_level(logging.ERROR):
            dag.build()

    assert hook_crashing.count == 1
    msg = 'Exception when running on_failure for DAG "dag": crash!'
    assert str(excinfo.value) == msg
    assert 'crash!' in str(excinfo.getrepr())
    assert dag._exec_status == DAGStatus.Errored
示例#5
0
def test_on_failure():
    on_failure_hook.count = 0
    on_failure_hook.traceback = None

    dag = DAG()
    PythonCallable(fn_that_fails, File('some_file.txt'), dag)
    dag.on_failure = on_failure_hook

    try:
        dag.build()
    except DAGBuildError:
        pass

    assert on_failure_hook.count == 1
    # check access to the traceback
    assert on_failure_hook.traceback['build']