Untitled

 avatar
unknown
plain_text
10 months ago
691 B
35
Indexable
import io
import sys
from qase.pytest import qase

def capture_stdout(func):
    def wrapper(*args, **kwargs):
        buffer = io.StringIO()
        sys_stdout = sys.stdout
        sys.stdout = buffer
        try:
            result = func(*args, **kwargs)
        finally:
            sys.stdout = sys_stdout
        qase.attach(
            (buffer.getvalue().encode(), "text/plain", "stdout.log")
        )
        return result
    return wrapper


@qase.step("A step that logs to stdout")
@capture_stdout
def my_step():
    print("Hello from stdout")
    print("Another line of logs")
    return True


def test_logs():
    with qase.step("Run logging step"):
        assert my_step()
Editor is loading...
Leave a Comment