77from unittest .mock import patch , mock_open , Mock , MagicMock
88
99from unittest import IsolatedAsyncioTestCase
10+ import nest_asyncio
1011
1112import runpod
1213from runpod ._version import __version__ as runpod_version
1314from runpod .serverless .modules .rp_logger import RunPodLogger
1415from runpod .serverless import _signal_handler
1516
17+ nest_asyncio .apply ()
18+
1619
1720class TestWorker (IsolatedAsyncioTestCase ):
1821 """ Tests for runpod | serverless| worker """
@@ -28,9 +31,8 @@ def setUp(self):
2831 "test_input" : None ,
2932 }
3033 }
31- os .environ ["RUNPOD_REALTIME_PORT" ] = '0'
3234
33- async def test_get_auth_header (self ):
35+ def test_get_auth_header (self ):
3436 '''
3537 Test _get_auth_header
3638 '''
@@ -43,7 +45,7 @@ async def test_get_auth_header(self):
4345 'User-Agent' : f'RunPod-Python-SDK/{ runpod_version } ({ os_info } ) Language/Python { platform .python_version ()} ' # pylint: disable=line-too-long
4446 }
4547
46- async def test_is_local (self ):
48+ def test_is_local (self ):
4749 '''
4850 Test _is_local
4951 '''
@@ -64,11 +66,12 @@ def test_start(self):
6466 '''
6567 with patch ("builtins.open" , mock_open (read_data = '{"input":{"number":1}}' )) as mock_file , \
6668 self .assertRaises (SystemExit ):
69+
6770 runpod .serverless .start ({"handler" : self .mock_handler })
6871
6972 assert mock_file .called
7073
71- async def test_is_local_testing (self ):
74+ def test_is_local_testing (self ):
7275 '''
7376 Test _is_local_testing
7477 '''
@@ -103,7 +106,7 @@ def test_local_api(self):
103106
104107 @patch ('runpod.serverless.log' )
105108 @patch ('runpod.serverless.sys.exit' )
106- async def test_signal_handler (self , mock_exit , mock_logger ):
109+ def test_signal_handler (self , mock_exit , mock_logger ):
107110 '''
108111 Test signal handler.
109112 '''
@@ -188,7 +191,7 @@ def setUp(self):
188191 @patch ("runpod.serverless.worker.stream_result" )
189192 @patch ("runpod.serverless.worker.send_result" )
190193 # pylint: disable=too-many-arguments
191- def test_run_worker (
194+ async def test_run_worker (
192195 self , mock_send_result , mock_stream_result , mock_run_job , mock_get_job , mock_session ):
193196 '''
194197 Test run_worker with synchronous handler.
@@ -219,7 +222,7 @@ def test_run_worker(
219222 @patch ("runpod.serverless.worker.run_job" )
220223 @patch ("runpod.serverless.worker.stream_result" )
221224 @patch ("runpod.serverless.worker.send_result" )
222- def test_run_worker_generator_handler (
225+ async def test_run_worker_generator_handler (
223226 self , mock_send_result , mock_stream_result , mock_run_job ,
224227 mock_get_job ):
225228 '''
@@ -251,7 +254,7 @@ def test_run_worker_generator_handler(
251254 @patch ("runpod.serverless.worker.run_job" )
252255 @patch ("runpod.serverless.worker.stream_result" )
253256 @patch ("runpod.serverless.worker.send_result" )
254- def test_run_worker_generator_handler_exception (
257+ async def test_run_worker_generator_handler_exception (
255258 self , mock_send_result , mock_stream_result , mock_run_job ,
256259 mock_get_job ):
257260 '''
@@ -283,7 +286,7 @@ def test_run_worker_generator_handler_exception(
283286 @patch ("runpod.serverless.worker.run_job" )
284287 @patch ("runpod.serverless.worker.stream_result" )
285288 @patch ("runpod.serverless.worker.send_result" )
286- def test_run_worker_generator_aggregate_handler (
289+ async def test_run_worker_generator_aggregate_handler (
287290 self , mock_send_result , mock_stream_result , mock_run_job ,
288291 mock_get_job ):
289292 '''
@@ -319,7 +322,7 @@ def test_run_worker_generator_aggregate_handler(
319322 @patch ("runpod.serverless.worker.stream_result" )
320323 @patch ("runpod.serverless.worker.send_result" )
321324 # pylint: disable=too-many-arguments
322- def test_run_worker_concurrency (
325+ async def test_run_worker_concurrency (
323326 self , mock_send_result , mock_stream_result , mock_run_job , mock_get_job , mock_session ):
324327 '''
325328 Test run_worker with synchronous handler.
@@ -358,7 +361,7 @@ def concurrency_modifier(current_concurrency):
358361 @patch ("runpod.serverless.worker.stream_result" )
359362 @patch ("runpod.serverless.worker.send_result" )
360363 # pylint: disable=too-many-arguments
361- def test_run_worker_multi_processing (
364+ async def test_run_worker_multi_processing (
362365 self , mock_send_result , mock_stream_result , mock_run_job , mock_get_job , mock_session ):
363366 '''
364367 Test run_worker with multi processing enabled, both async and generator handler.
@@ -417,7 +420,7 @@ def test_run_worker_multi_processing(
417420
418421 @patch ("runpod.serverless.modules.rp_scale.get_job" )
419422 @patch ("runpod.serverless.worker.run_job" )
420- def test_run_worker_multi_processing_scaling_up (
423+ async def test_run_worker_multi_processing_scaling_up (
421424 self , mock_run_job , mock_get_job ):
422425 '''
423426 Test run_worker with multi processing enabled, the scale-up and scale-down
@@ -463,7 +466,7 @@ def mock_is_alive():
463466 runpod .serverless .start (config )
464467
465468 # Test with sls-core
466- def test_run_worker_with_sls_core (self ):
469+ async def test_run_worker_with_sls_core (self ):
467470 '''
468471 Test run_worker with sls-core.
469472 '''
0 commit comments