File: test_wrap_with_logs.py

package info (click to toggle)
python-parsl 2025.01.13%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,072 kB
  • sloc: python: 23,817; makefile: 349; sh: 276; ansic: 45
file content (34 lines) | stat: -rw-r--r-- 742 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import logging

import pytest

from parsl.process_loggers import wrap_with_logs


@wrap_with_logs
def somefunc_ok():
    return 5


@wrap_with_logs
def somefunc_exception():
    raise RuntimeError("Deliberate failure")


@pytest.mark.local
def test_wrap_with_logs_ok(caplog):
    caplog.set_level(logging.DEBUG)

    # check that return value is passed back through wrap_with_logs
    x = somefunc_ok()
    assert x == 5
    assert 'Normal ending' in caplog.text


@pytest.mark.local
def test_wrap_with_logs_exception(caplog):
    caplog.set_level(logging.ERROR)
    # check that exception is passed back through wrap_with_logs
    with pytest.raises(RuntimeError):
        somefunc_exception()
    assert 'Exceptional ending' in caplog.text