fixed session scope
This commit is contained in:
@@ -1,12 +1,64 @@
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
from appdaemon.appdaemon import AppDaemon
|
||||
from appdaemon.logging import Logging
|
||||
from appdaemon.models.config import AppDaemonConfig
|
||||
from git import Repo
|
||||
from pytest import Function
|
||||
|
||||
from .utils import delayed_stop
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(session, config, items: List[Function]):
|
||||
for i, item in enumerate(items):
|
||||
if isinstance(item, Function) and "startup" in item.name:
|
||||
if isinstance(item, Function) and 'startup' in item.name:
|
||||
items.insert(0, items.pop(i))
|
||||
break
|
||||
|
||||
return items
|
||||
|
||||
|
||||
CONFIG_DIR = Path(__file__).parents[2] / 'conf'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_repo() -> Repo:
|
||||
repo = Repo('/home/john/ad-test')
|
||||
return repo
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def base_config() -> AppDaemonConfig:
|
||||
return AppDaemonConfig(
|
||||
latitude=0.0,
|
||||
longitude=0.0,
|
||||
elevation=0,
|
||||
time_zone='America/Chicago',
|
||||
config_dir=CONFIG_DIR,
|
||||
config_file='appdaemon.yaml',
|
||||
# stop_function=lambda: print('Stopping'),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def ad(base_config: AppDaemonConfig):
|
||||
# logging.getLogger('AppDaemon._app_management').setLevel('DEBUG')
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
|
||||
ad = AppDaemon(Logging(), loop, base_config)
|
||||
yield ad
|
||||
ad.stop()
|
||||
|
||||
tasks = asyncio.all_tasks(loop)
|
||||
for t in tasks:
|
||||
t.cancel()
|
||||
|
||||
with pytest.raises(asyncio.exceptions.CancelledError):
|
||||
loop.run_until_complete(asyncio.gather(*tasks))
|
||||
|
||||
loop.close()
|
||||
print('Cleaned up running AD')
|
||||
|
||||
Reference in New Issue
Block a user