Skip to content

Instantly share code, notes, and snippets.

@reinaldons
Created May 8, 2013 00:13
Show Gist options
  • Save reinaldons/5537246 to your computer and use it in GitHub Desktop.
Save reinaldons/5537246 to your computer and use it in GitHub Desktop.
MongoDB with no disk file persist
import socket
from time import sleep
import os
import unittest
import tempfile
from subprocess import Popen, PIPE
from flask import url_for
import flaskr
def is_open(ip,port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, int(port)))
s.shutdown(2)
return True
except:
return False
class FlaskrTestCase(unittest.TestCase):
@classmethod
def setUpClass(self):
try:
os.mkdir('test_db')
except Exception, e:
pass
self.mongod = Popen(['mongod', '--smallfiles', '--noprealloc', '--syncdelay', '0', '--nojournal', '--dbpath', 'test_db' ], stdout=PIPE)
while not is_open('localhost', 27017):
sleep(0.1)
@classmethod
def tearDownClass(self):
self.mongod.terminate()
while is_open('localhost', 27017):
sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment