Files
OpenBB/tests/helpers.py
colin99d 81337b4fdd Improved Testing Framework (#665)
* Reduced test time by 85% using vcrpy

* Refactored tests with decorator

* Added vcrpy dependencies

* Fixed issues with tests

* Fixed tests not running in local

Co-authored-by: Colin Delahunty <colindelahunty@Colins-Air.attlocal.net>
2021-08-13 12:05:32 -04: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