mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* Updating tests : stocsk > helper * Updating tests : doc * Updating tests : stop new cassettes generation * Updating tests : group helpers * Updating tests : black * Updating tests : path for parameterize_from_file
27 lines
719 B
Python
27 lines
719 B
Python
import functools
|
|
import sys
|
|
import io
|
|
|
|
|
|
def check_print(assert_in: str = "", length: int = -1):
|
|
"""Captures output of print function and checks if the function contains a given string"""
|
|
|
|
def checker(func):
|
|
@functools.wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
func(*args, **kwargs)
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
if assert_in:
|
|
assert assert_in in capt
|
|
return None
|
|
if length >= 0:
|
|
assert len(capt) > length
|
|
return capt
|
|
|
|
return wrapper
|
|
|
|
return checker
|