title: How can I test a Flask application which uses SQLAlchemy?
body: <p>I have a working web application on Flask with SqlAlchemy for moderation of news, it has some api methods to handle moderation requests, such as approve, deny currently selected news, list them, etc.</p>
  
  <p>I want to write unit tests to this methods, and I made them work, but I don't understand how to implement executing all requests which I do from test cases in one db session, so that I could remove all changes to database. Or is there another cleaner or proper way to do this?</p>
  
  <p>I've found out that maybe all I need is "scoped_session" in SqlAlchemy, but all my attempts to implement it have failed. If that's correct way, please, tell me where to use this lines of code (in settings, or in test case set_up method).     </p>
  
  <pre><code>from sqlalchemy.orm import scoped_session
  from sqlalchemy.orm import sessionmaker
  session_factory = sessionmaker()
  Session = scoped_session(session_factory) 
  </code></pre>