def setup_mc(): """Lance un serveur memcached pour les tests.""" global mc_pid # Juste pour être sûr... if mc_pid: LOGGER.info("Forcefully stopping previous instance of memcached") teardown_mc() settings['correlator']['memcached_host'] = "127.0.0.1" port = get_available_port() settings['correlator']['memcached_port'] = port env = os.environ.copy() env["PATH"] += ":/usr/sbin" # Sur mandriva, memcached est dans /usr/sbin LOGGER.info("Configuring memcached to run on port %d", port) mc_pid = subprocess.Popen(["memcached", "-l", "127.0.0.1", "-p", str(port)], env=env, close_fds=True).pid # Give it time to start up properly. I should try a client connection in a # while loop. Oh well... MemcachedConnection.reset() time.sleep(1) MemcachedConnection()
def teardown_mc(): """Détruit le serveur memcached créé pour le passage d'un test.""" global mc_pid LOGGER.info("Killing memcached instance running on port %d", settings['correlator']['memcached_port']) try: # Tue le serveur memcached lancé en arrière-plan. os.kill(mc_pid, signal.SIGTERM) os.wait() # Avoid zombies. Bad zombies. except OSError, e: # We mostly ignore errors, maybe we should # do something more useful here. print e finally: mc_pid = None return MemcachedConnection.reset() with_mc = nose.with_setup(setup_mc, teardown_mc) #Create an empty database before we start our tests for this module def setup_db(): """Crée toutes les tables du modèle dans la BDD.""" from vigilo.models.tables.grouppath import GroupPath from vigilo.models.tables.usersupitem import UserSupItem tables = metadata.tables.copy() del tables[GroupPath.__tablename__] del tables[UserSupItem.__tablename__] metadata.create_all(tables=tables.itervalues()) metadata.create_all(tables=[GroupPath.__table__, UserSupItem.__table__]) #Teardown that database