@@ -100,6 +100,7 @@ def run(self) -> None:
100100 env = {
101101 "ALS" : self .env .als ,
102102 "ALS_HOME" : self .env .als_home ,
103+ "ALS_WAIT_FACTOR" : str (self .env .wait_factor ),
103104 "PYTHONPATH" : os .path .dirname (os .path .dirname (__file__ )),
104105 }
105106
@@ -118,14 +119,16 @@ def run(self) -> None:
118119 if r .status != 0 :
119120 raise TestAbortWithFailure ("non-zero status code" )
120121 else :
122+ # Usually we specify a timeout here, however a test file may
123+ # contain multiple tests. So instead we apply a timeout to each
124+ # test in async_wrapper()
121125 p : ProcessResult = self .shell (
122126 cmd ,
123127 # Start the test process directly in the test work dir. This way
124128 # tests can simply assume that the current dir is the test work dir.
125129 cwd = str (wd ),
126130 env = env ,
127131 ignore_environ = False ,
128- timeout = 15 , # seconds
129132 stdin = None ,
130133 )
131134
@@ -477,6 +480,11 @@ def assertLocationsList(
477480 """
478481 assertLocationsList (actual , expected )
479482
483+ async def sleep (self , seconds : float ) -> None :
484+ """Wait for the given amount of seconds multiplied by ALS_WAIT_FACTOR."""
485+ wait_factor : int = int (os .environ .get ("ALS_WAIT_FACTOR" , "1" ))
486+ await asyncio .sleep (seconds * wait_factor )
487+
480488
481489def als_client_factory () -> ALSLanguageClient :
482490 """This function is an ugly copy-paste of pytest_lsp.make_test_lsp_client. It is
@@ -591,6 +599,8 @@ def test(
591599 initialize : bool = True ,
592600 shutdown : bool = True ,
593601 assert_no_lsp_errors : bool = True ,
602+ als_settings : ALSSettings | None = None ,
603+ timeout = 15 ,
594604) -> Callable :
595605 """A decorator to mark a function as a test entry point. The function must receive a
596606 single parameter of type LanguageClient.
@@ -618,6 +628,9 @@ def test(
618628 of the test function.
619629 :param assert_no_lsp_errors: automatically assert that no LSP log message of level
620630 error were received after the end of the test function.
631+ :param als_settings: ALS settings to send as 'initializationOptions' with the
632+ 'initialize' request. Only applicable if initialize=True (which is the default).
633+ :param timeout: test timeout in seconds
621634 """
622635
623636 async def async_wrapper (
@@ -642,13 +655,22 @@ async def async_wrapper(
642655 # ALS doesn't support the newer workspaceFolders property so we
643656 # have to use the older rootURI property.
644657 root_uri = URI (os .getcwd ()),
658+ initialization_options = (
659+ {"ada" : als_settings } if als_settings is not None else None
660+ ),
645661 )
646662 )
647663
648664 LOG .info ("Running test function: %s" , func .__name__ )
649665
650- # Run the test
651- await func (client )
666+ actual_timeout = timeout
667+ if "ALS_WAIT_FACTOR" in os .environ :
668+ factor = int (os .environ ["ALS_WAIT_FACTOR" ])
669+ actual_timeout *= factor
670+
671+ # Run the test with a timeout
672+ async with asyncio .timeout (actual_timeout ):
673+ await func (client )
652674
653675 if assert_no_lsp_errors :
654676 # Assert the absence of Error LSP log messages
0 commit comments