forked from BrewBlox/brewblox-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
53 lines (38 loc) · 1.16 KB
/
conftest.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Master file for pytest fixtures.
Any fixtures declared here are available to all test functions in this directory.
"""
import logging
import pytest
from brewblox_service import service
@pytest.fixture(scope='session', autouse=True)
def log_enabled():
"""Sets log level to DEBUG for all test functions.
Allows all logged messages to be captured during pytest runs"""
logging.getLogger().setLevel(logging.DEBUG)
@pytest.fixture
def app_config() -> dict:
return {
'name': 'test_app',
'host': 'localhost',
'port': 1234,
'debug': False,
}
@pytest.fixture
def sys_args(app_config) -> list:
return [
'app_name',
'--name', app_config['name'],
'--host', app_config['host'],
'--port', str(app_config['port']),
]
@pytest.fixture
def app(sys_args):
app = service.create_app('default', raw_args=sys_args[1:])
return app
@pytest.fixture
def client(app, aiohttp_client, loop):
"""Allows patching the app or aiohttp_client before yielding it.
Any tests wishing to add custom behavior to app can override the fixture
"""
return loop.run_until_complete(aiohttp_client(app))