Skip to content

Commit 90d3de0

Browse files
committed
test: force clean Unity state on test startup
1 parent c3fac60 commit 90d3de0

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

sample/Tests/test/test_windows.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class WindowsTest(UnityTest):
99

1010
@classmethod
1111
def setUpClass(cls):
12-
open_sample_app()
12+
# Clear cached login state at the start of the test suite
13+
open_sample_app(clear_data=True)
1314
time.sleep(5) # Give time for the app to open
1415
# Initialize AltDriver with longer timeout for flaky CI environment
1516
cls.altdriver = AltDriver(timeout=120) # 120 seconds instead of default 20
@@ -22,7 +23,7 @@ def tearDownClass(cls):
2223
def restart_app_and_altdriver(self):
2324
self.stop_altdriver()
2425
stop_sample_app()
25-
open_sample_app()
26+
open_sample_app() # Normal restart without clearing data
2627
time.sleep(5) # Give time for the app to open
2728
# Use same timeout as setUpClass
2829
self.__class__.altdriver = AltDriver(timeout=120)

sample/Tests/test/test_windows_helpers.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,51 @@ def login():
527527
# Keep browser alive for Unity deep link redirect
528528
# driver.quit()
529529

530-
def open_sample_app():
530+
def clear_unity_data():
531+
"""Clear Unity's persistent data to force fresh start"""
532+
print("Clearing Unity persistent data...")
533+
534+
# Clear PlayerPrefs from Windows Registry
535+
try:
536+
import winreg
537+
registry_path = r"SOFTWARE\Immutable\Immutable Sample"
538+
539+
# Try both HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE
540+
for root_key in [winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE]:
541+
try:
542+
winreg.DeleteKey(root_key, registry_path)
543+
print(f"Cleared PlayerPrefs from registry: {root_key}")
544+
except FileNotFoundError:
545+
pass # Key doesn't exist, that's fine
546+
except Exception as e:
547+
print(f"Could not clear registry {root_key}: {e}")
548+
549+
except ImportError:
550+
print("Windows registry module not available")
551+
except Exception as e:
552+
print(f"Error clearing registry: {e}")
553+
554+
# Clear Application.persistentDataPath
555+
try:
556+
data_path = os.path.join(os.path.expanduser("~"), "AppData", "LocalLow", "Immutable", "Immutable Sample")
557+
if os.path.exists(data_path):
558+
import shutil
559+
shutil.rmtree(data_path)
560+
print(f"Cleared persistent data folder: {data_path}")
561+
else:
562+
print(f"No persistent data folder found at: {data_path}")
563+
except Exception as e:
564+
print(f"Error clearing persistent data: {e}")
565+
566+
print("Unity data cleanup complete")
567+
568+
def open_sample_app(clear_data=False):
531569
product_name = get_product_name()
570+
571+
# Clear any cached login state before opening (only when requested)
572+
if clear_data:
573+
clear_unity_data()
574+
532575
print(f"Opening {product_name}...")
533576
subprocess.Popen([f"{product_name}.exe"], shell=True)
534577
time.sleep(10)

0 commit comments

Comments
 (0)