added try statement

This commit is contained in:
John Lancaster
2024-08-12 22:15:15 -05:00
parent 1358da1e60
commit e3873f5510
2 changed files with 12 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import logging
from pathlib import Path
from typing import List
@@ -45,6 +46,7 @@ def ad(base_config: AppDaemonConfig):
loop = asyncio.new_event_loop()
ad = AppDaemon(Logging(), loop, base_config)
logging.getLogger('AppDaemon').propagate = True
yield ad
ad.stop()

View File

@@ -24,7 +24,7 @@ def modify_file(path: Path):
path.write_text(modified_content)
def insert_importerror(path: Path):
def insert_import_error(path: Path):
file_content = path.read_text().splitlines()
file_content.insert(0, 'raise ImportError')
path.write_text('\n'.join(file_content))
@@ -36,7 +36,7 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo
module_file = Path(food.meal.__file__)
modify_file(module_file)
logging.getLogger('AppDaemon').propagate = True
try:
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):
ad.loop.run_until_complete(asyncio.sleep(1.0))
@@ -45,13 +45,15 @@ def test_file(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo
reset_file(config_repo, module_file)
ad.loop.run_until_complete(asyncio.sleep(1.0))
finally:
reset_file(config_repo, module_file)
def test_file_with_error(ad: AppDaemon, caplog: pytest.LogCaptureFixture, config_repo: Repo):
assert isinstance(ad, AppDaemon)
module_file = Path(food.meal.__file__)
insert_importerror(module_file)
insert_import_error(module_file)
try:
with caplog.at_level(logging.DEBUG, logger='AppDaemon._app_management'):