@@ -96,6 +96,7 @@ def get_ready_to_test_action(launch_description):
9696def pytest_fixture_setup (fixturedef , request ):
9797 """Set up launch service for all launch_pytest fixtures."""
9898 if getattr (fixturedef .func , '_launch_pytest_fixture' , False ):
99+ options = fixturedef .func ._launch_pytest_fixture_options
99100 eprefix = f"When running launch_pytest fixture '{ fixturedef .func .__name__ } ':"
100101 ls = request .getfixturevalue ('launch_service' )
101102 event_loop = request .getfixturevalue ('event_loop' )
@@ -114,14 +115,14 @@ def pytest_fixture_setup(fixturedef, request):
114115 ls .include_launch_description (ld )
115116 run_async_task = event_loop .create_task (ls .run_async (
116117 # TODO(ivanpauno): maybe this could be configurable (?)
117- shutdown_when_idle = True
118+ shutdown_when_idle = options [ 'shutdown_when_idle' ]
118119 ))
119120 ready = get_ready_to_test_action (ld )
120121 asyncio .set_event_loop (event_loop )
121122 event = asyncio .Event ()
122123 ready ._add_callback (lambda : event .set ())
123-
124- fixturedef . addfinalizer ( functools . partial ( finalize_launch_service , ls , eprefix = eprefix ))
124+ fixturedef . addfinalizer ( functools . partial (
125+ finalize_launch_service , ls , eprefix = eprefix , auto_shutdown = options [ 'auto_shutdown' ] ))
125126 run_until_complete (event_loop , event .wait ())
126127 # this is guaranteed by the current run_async() implementation, let's check it just in case
127128 # it changes in the future
@@ -343,8 +344,12 @@ def pytest_pyfunc_call(pyfuncitem):
343344 scope = fixture ._pytestfixturefunction .scope
344345 event_loop = pyfuncitem .funcargs ['event_loop' ]
345346 ls = pyfuncitem .funcargs ['launch_service' ]
347+ auto_shutdown = fixture ._launch_pytest_fixture_options ['auto_shutdown' ]
346348 on_shutdown = functools .partial (
347- finalize_launch_service , ls , eprefix = f'When running test { func .__name__ } ' )
349+ finalize_launch_service ,
350+ ls ,
351+ eprefix = f'When running test { func .__name__ } ' ,
352+ auto_shutdown = auto_shutdown )
348353 before_test = on_shutdown if shutdown_test else None
349354 if inspect .iscoroutinefunction (func ):
350355 pyfuncitem .obj = wrap_coroutine (func , event_loop , before_test )
0 commit comments