Files
OpenBB/tests/helpers/helpers.py
Chavithra 67e1ecf986 Tests : Stocks + Crypto + Helpers (#1046)
* 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
2021-12-09 20:48:58 +01:00

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