Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trouble capturing stdout in test #123

Open
aedenj opened this issue Apr 16, 2018 · 0 comments
Open

trouble capturing stdout in test #123

aedenj opened this issue Apr 16, 2018 · 0 comments

Comments

@aedenj
Copy link

aedenj commented Apr 16, 2018

I'm attempting to write some tests around telemetry of a flask app using pytest asserting on the contents of stdout. Suppose I have this app,

imports ...

app = Flask(__name__)

@app.route("/")
def hello():
    return "hello"

@app.before_first_request
def app_start():
    app.logger.addHandler(logging.StreamHandler(sys.stdout))
    app.logger.setLevel(logging.INFO)

@app.after_request
def after_request(response):
   app.logger.info('signal')

and this test

imports ...

__flask__ = app.test_client()
__flask__.testing = True


def test_endpoint_produces_signal(capsys):
    __flask__.get('/')
    out, err = capsys.readouterr()
    assert out == 'signal'

Unfortunately this test fails. However, if I move the logging configuration and info call all to after_request is works. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant