mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-26 07:35:44 -03:00
refactor(tests): enhance async test handling in pytest_pyfunc_call
This commit is contained in:
@@ -42,8 +42,30 @@ sys.modules['nodes'] = nodes_mock
|
|||||||
|
|
||||||
|
|
||||||
def pytest_pyfunc_call(pyfuncitem):
|
def pytest_pyfunc_call(pyfuncitem):
|
||||||
if inspect.iscoroutinefunction(pyfuncitem.function):
|
"""Allow bare async tests to run without pytest.mark.asyncio."""
|
||||||
asyncio.run(pyfuncitem.obj(**pyfuncitem.funcargs))
|
test_function = pyfuncitem.function
|
||||||
|
if inspect.iscoroutinefunction(test_function):
|
||||||
|
func = pyfuncitem.obj
|
||||||
|
signature = inspect.signature(func)
|
||||||
|
accepted_kwargs: Dict[str, Any] = {}
|
||||||
|
for name, parameter in signature.parameters.items():
|
||||||
|
if parameter.kind is inspect.Parameter.VAR_POSITIONAL:
|
||||||
|
continue
|
||||||
|
if parameter.kind is inspect.Parameter.VAR_KEYWORD:
|
||||||
|
accepted_kwargs = dict(pyfuncitem.funcargs)
|
||||||
|
break
|
||||||
|
if name in pyfuncitem.funcargs:
|
||||||
|
accepted_kwargs[name] = pyfuncitem.funcargs[name]
|
||||||
|
|
||||||
|
original_policy = asyncio.get_event_loop_policy()
|
||||||
|
policy = pyfuncitem.funcargs.get("event_loop_policy")
|
||||||
|
if policy is not None and policy is not original_policy:
|
||||||
|
asyncio.set_event_loop_policy(policy)
|
||||||
|
try:
|
||||||
|
asyncio.run(func(**accepted_kwargs))
|
||||||
|
finally:
|
||||||
|
if policy is not None and policy is not original_policy:
|
||||||
|
asyncio.set_event_loop_policy(original_policy)
|
||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -196,3 +218,5 @@ def mock_scanner(mock_cache: MockCache, mock_hash_index: MockHashIndex) -> MockS
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_service(mock_scanner: MockScanner) -> MockModelService:
|
def mock_service(mock_scanner: MockScanner) -> MockModelService:
|
||||||
return MockModelService(scanner=mock_scanner)
|
return MockModelService(scanner=mock_scanner)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user