Skip to content

Instantly share code, notes, and snippets.

@nijotz
Created November 20, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nijotz/842a94fc8d43491d9098 to your computer and use it in GitHub Desktop.
Save nijotz/842a94fc8d43491d9098 to your computer and use it in GitHub Desktop.
Test mail being sent in Flask Selenium tests
def _worker(app, port, queue):
from flask.ext.mail import email_dispatched
def queue_message(message, app):
if app.testing:
queue.put(message)
email_dispatched.connect(queue_message)
app.run(port=port)
class MailServerTestCase(LiveServerTestCase):
def _spawn_live_server(self):
self._process = None
self.port = self.app.config.get('LIVESERVER_PORT', 5000)
self.outbox = Queue()
self._process = multiprocessing.Process(
target=_worker, args=(self.app, self.port, self.outbox)
)
self._process.start()
# we must wait the server start listening
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment