diff options
author | Cheng Shao <terrorjack@type.dance> | 2023-03-13 08:18:11 +0000 |
---|---|---|
committer | Cheng Shao <terrorjack@type.dance> | 2023-03-30 18:43:53 +0000 |
commit | 0149f32fc8cc805ff368e5b3e36051d0d1898550 (patch) | |
tree | b4e7c82b04e78bca44bc21fb1f69ea3348500a2b | |
parent | 8fe8b65390bdbd6b51af42a227300c46cca89b3b (diff) | |
download | haskell-0149f32fc8cc805ff368e5b3e36051d0d1898550.tar.gz |
testsuite: use context variable instead of thread-local variable
This patch changes a thread-local variable to context variable
instead, which works as intended when the testsuite transitions to use
asyncio & coroutines instead of multi-threading to concurrently run
test cases. Note that this also raises the minimum Python version to
3.7.
-rw-r--r-- | testsuite/driver/runtests.py | 2 | ||||
-rw-r--r-- | testsuite/driver/testlib.py | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/testsuite/driver/runtests.py b/testsuite/driver/runtests.py index 7f8c7ffff1..b814a63937 100644 --- a/testsuite/driver/runtests.py +++ b/testsuite/driver/runtests.py @@ -309,7 +309,7 @@ if windows: path = format_path(path) ghc_env['PATH'] = os.pathsep.join([path, ghc_env.get("PATH", "")]) -testopts_local.x = TestOptions() +testopts_ctx_var.set(TestOptions()) # if timeout == -1 then we try to calculate a sensible value if config.timeout == -1: diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index bf0ec0b3a8..b5f68b20dd 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -36,7 +36,7 @@ from my_typing import * from threading import Timer from collections import OrderedDict -import threading +import contextvars global wantToStop wantToStop = False @@ -80,15 +80,15 @@ def get_all_ways() -> Set[WayName]: # Options valid for the current test only (these get reset to # testdir_testopts after each test). -global testopts_local -testopts_local = threading.local() +global testopts_ctx_var +testopts_ctx_var = contextvars.ContextVar('testopts_ctx_var') # type: ignore def getTestOpts() -> TestOptions: - return testopts_local.x + return testopts_ctx_var.get() def setLocalTestOpts(opts: TestOptions) -> None: - global testopts_local - testopts_local.x = opts + global testopts_ctx_var + testopts_ctx_var.set(opts) def isCross() -> bool: """ Are we testing a cross-compiler? """ |