Snippet para usar un unittest con un proceso separado

Necsitaba probar un api rest y se me ocurrio levantar bottle en un proceso separado dentro de un testcase; y necesite hacer todos este chicle.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# <> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a WISKEY in return Juan BC

import multiprocessing
import urllib2
import unittest

import bottle

class BottleTest(unittest.TestCase):

    def setUp(self):
        self.process = multiprocessing.Process(
            kwargs={"port": "8081"}

        # wait until bottle process full started
        # si no ponen esto el testcase se va a ejecutar antes
        # que bottle este listo para recibir peticiones
        started = False
        while not started:
            except urllib2.HTTPError:
                started = True
            except urllib2.URLError as err:
                if err.reason.args[0] == 111:
                    raise err
                started = True

    def tearDown(self):

    def test_something(self):

One thought on “Snippet para usar un unittest con un proceso separado

  1. Very nice post. I just stumbled upon your blog and wanted to
    say that I have really enjoyed browsing your blog posts.
    After all I’ll be subscribing to your rss feed and I hope you write again soon!

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>