Reset values after PlayMode test

I have a code like this

public static class TestClass
{
    private static bool initialized;
    public static void Initialize()
    {
        if (initialized) throw new Exception("TestClass already initialized.");
        initialized = true;
    }
}

[UnityTest]
public IEnumerator Test1()
{
    TestClass.Initialize();
    yield break;
}
[UnityTest]
public IEnumerator Test2()
{
    TestClass.Initialize();
    yield break;
}

If I run Test1 and Test2 by “Run Selected”, tests passed. But if i press “Run All” - second failed. Also, tests can create new game objects, thread, etc. How I can clear it?

Static fields won’t be reset in between test runs. Try looking at SetupAttribute for code initiation and either make your class non-static, convert it into a singleton or introduce a reset method to reset the state of the static class