Replace the "TestError" global variable with a module state structure. <!-- gh-linked-prs --> ### Linked PRs * gh-113634 <!-- /gh-linked-prs -->