File: conftest.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (40 lines) | stat: -rw-r--r-- 861 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import subprocess
import sys
import time

import requests

LOOK_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

gunicorn = None


def pytest_sessionstart(session):
    global gunicorn

    gunicorn = subprocess.Popen(
        (
            sys.executable,
            '-m',
            'gunicorn',
            '--pythonpath',
            LOOK_PATH,
            'look.app:get_app()',
        ),
        env=dict(os.environ, LOOK_STORAGE_PATH='/tmp'),
    )

    # NOTE(vytas): give Gunicorn some time to start.
    for attempt in range(3):
        try:
            requests.get('http://127.0.0.1/images', timeout=1)
            break
        except requests.exceptions.RequestException:
            pass
        time.sleep(0.2)


def pytest_sessionfinish(session, exitstatus):
    gunicorn.terminate()
    gunicorn.communicate()