Created
March 9, 2011 13:47
-
-
Save jbking/862204 to your computer and use it in GitHub Desktop.
wait external process started before testing and kill before exit in teardown in testing cycle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import socket | |
import xmlrpclib | |
import subprocess | |
here = os.path.dirname(os.path.abspath(__file__)) | |
target = os.path.join(here, 'server.py') | |
gateway = None | |
def setup(): | |
global gateway | |
gateway = subprocess.Popen([target]) | |
while True: | |
try: | |
sock = socket.create_connection(('localhost', 9000)) | |
sock.close() | |
break | |
except: | |
time.sleep(0.1) | |
def test_add(): | |
proxy = xmlrpclib.ServerProxy('http://localhost:9000') | |
assert proxy.add(5, 7) == 12 | |
def teardown(): | |
global gateway | |
gateway.terminate() | |
gateway.wait() | |
if __name__ == '__main__': | |
setup() | |
try: | |
test_add() | |
except: | |
pass | |
teardown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment