@@ -496,25 +496,42 @@ def test_cancelled_dialog_is_no_op(self, window, monkeypatch):
496496
497497
498498class TestConfigPersistence :
499+ @pytest .fixture (autouse = True )
500+ def isolated_settings (self , tmp_path , monkeypatch ):
501+ """Redirect QSettings to a temp ini file — never touches real user prefs.
502+
503+ Patches src.views.main_window.QSettings so _save_settings and
504+ _load_settings both hit the temp file. Stores the path on self so test
505+ bodies can construct a matching QSettings instance to read/clear it.
506+ """
507+ from PySide6 .QtCore import QSettings
508+ tmp_ini = str (tmp_path / "test_settings.ini" )
509+ monkeypatch .setattr (
510+ "src.views.main_window.QSettings" ,
511+ lambda * _ : QSettings (tmp_ini , QSettings .Format .IniFormat ),
512+ )
513+ # Expose path so test bodies read/clear the SAME file the window uses
514+ self ._tmp_ini = tmp_ini
515+
499516 def test_save_settings_writes_geometry (self , window , qtbot ):
500517 """_save_settings must write window/geometry to QSettings."""
501518 from PySide6 .QtCore import QSettings
502- s = QSettings ("TextTools" , "TextTools" )
519+ # Clear geometry in the same temp file the window will write to
520+ s = QSettings (self ._tmp_ini , QSettings .Format .IniFormat )
503521 s .remove ("window/geometry" )
504522 window .ui .show ()
505523 window ._save_settings ()
506- s2 = QSettings ("TextTools" , "TextTools" )
524+ s2 = QSettings (self . _tmp_ini , QSettings . Format . IniFormat )
507525 assert s2 .value ("window/geometry" ) is not None
508526
509527 def test_load_settings_does_not_raise_when_empty (self , window ):
510528 """_load_settings must not raise when no settings have been saved."""
511529 from PySide6 .QtCore import QSettings
512- QSettings ("TextTools" , "TextTools" ).clear ()
530+ QSettings (self . _tmp_ini , QSettings . Format . IniFormat ).clear ()
513531 window ._load_settings () # must not raise
514532
515533 def test_save_and_restore_geometry (self , window , qtbot ):
516534 """Geometry saved by _save_settings is restored by _load_settings."""
517- from PySide6 .QtCore import QSettings
518535 window .ui .show ()
519536 window .ui .resize (700 , 600 )
520537 qtbot .wait (10 )
0 commit comments