T
T
twintwin10032016-01-31 15:59:47
Software testing
twintwin1003, 2016-01-31 15:59:47

Flask testing?

It is necessary to test the functionality of the server written in Flask. Moved application initialization to create_app()

from flask import Flask

def create_app(debug=False):
    app = Flask(__name__)
    app.debug = debug

    return app


Next, I write tests using Nose . And there was such a problem, if I have several test cases, then the same application is used. In other words, with a new case, the server remains the same, which is rather inconvenient, because the cases are written taking into account that the server has just risen.
I googled, found that you can create factories in Flask, just through create_app (), but no matter how I tried, there is still one single instance of my application. Or maybe you can somehow drop it and restart it?

I'll listen to any ideas :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-01-31
@EvilsInterrupt

There is a book by Miguel Greenberg about web development with Flask. I recommend reading the sections about testing. I deliberately will not give how, because. better than Grinberg, hardly anyone can explain it better. But. I would like to draw your attention to the fact that it is better to use py.test + pyhamcrest instead of Nose , then your tests will be more expressive and you will be able to see better "What would .. break that?"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question