diff options
Diffstat (limited to 'httpcache/conftest.py')
-rw-r--r-- | httpcache/conftest.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/httpcache/conftest.py b/httpcache/conftest.py new file mode 100644 index 00000000..2fe30f8a --- /dev/null +++ b/httpcache/conftest.py @@ -0,0 +1,41 @@ +import os +import py.test +import subprocess +import requests +import time + + +class TestServer(object): + + def start(self): + base = os.path.abspath(os.path.dirname(__file__)) + server_file = os.path.join(base, 'httpcache', 'tests', 'server.py') + cmd = ['python', server_file] + + kw = {} + if not os.environ.get('TEST_SERVER_OUTPUT'): + kw = {'stdout': subprocess.PIPE, + 'stderr': subprocess.STDOUT} + self.proc = subprocess.Popen(cmd, **kw) + url = 'http://localhost:8080' + up = None + while not up: + try: + up = requests.get(url) + except requests.ConnectionError: + time.sleep(1) + + def stop(self): + self.proc.terminate() + + +def pytest_namespace(): + return dict(server=TestServer()) + + +def pytest_configure(config): + py.test.server.start() + + +def pytest_unconfigure(config): + py.test.server.stop() |