@@ -54,6 +54,34 @@ def root():
5454 os .environ ["TK_SILENCE_DEPRECATION" ] = "1"
5555 os .environ ["PYTHONUNBUFFERED" ] = "1"
5656
57+ # Ensure DISPLAY is set for headless environments
58+ if "DISPLAY" not in os .environ :
59+ os .environ ["DISPLAY" ] = ":0.0"
60+
61+ # Set TCL_LIBRARY environment variable to help with Tcl initialization
62+ import sys
63+ if hasattr (sys , 'frozen' ):
64+ # Running as compiled executable
65+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
66+ else :
67+ # Running as script
68+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
69+
70+ # Try to find Tcl library directory
71+ if os .path .exists (tcl_dir ):
72+ os .environ ["TCL_LIBRARY" ] = tcl_dir
73+ else :
74+ # Try alternative paths
75+ alternative_paths = [
76+ os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' ),
77+ os .path .join (os .path .dirname (sys .executable ), '..' , 'tcl' , 'tcl8.6' ),
78+ os .path .join (os .path .dirname (sys .executable ), '..' , '..' , 'tcl' , 'tcl8.6' ),
79+ ]
80+ for alt_path in alternative_paths :
81+ if os .path .exists (alt_path ):
82+ os .environ ["TCL_LIBRARY" ] = alt_path
83+ break
84+
5785 # Create new root window for each test
5886 temp_root = tk .Tk ()
5987 temp_root .withdraw () # Hide the main window
@@ -103,6 +131,9 @@ def root():
103131 "$DISPLAY environment variable" ,
104132 "application has been destroyed" ,
105133 "invalid command name \" tcl_findLibrary\" " ,
134+ "couldn't read file" ,
135+ "Tcl wasn't installed properly" ,
136+ "Tcl initialization" ,
106137 ]
107138 ):
108139 pytest .skip (
@@ -134,6 +165,35 @@ def root_function():
134165 try :
135166 # Set environment variables
136167 os .environ ["TK_SILENCE_DEPRECATION" ] = "1"
168+
169+ # Ensure DISPLAY is set for headless environments
170+ if "DISPLAY" not in os .environ :
171+ os .environ ["DISPLAY" ] = ":0.0"
172+
173+ # Set TCL_LIBRARY environment variable to help with Tcl initialization
174+ import sys
175+ if hasattr (sys , 'frozen' ):
176+ # Running as compiled executable
177+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
178+ else :
179+ # Running as script
180+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
181+
182+ # Try to find Tcl library directory
183+ if os .path .exists (tcl_dir ):
184+ os .environ ["TCL_LIBRARY" ] = tcl_dir
185+ else :
186+ # Try alternative paths
187+ alternative_paths = [
188+ os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' ),
189+ os .path .join (os .path .dirname (sys .executable ), '..' , 'tcl' , 'tcl8.6' ),
190+ os .path .join (os .path .dirname (sys .executable ), '..' , '..' , 'tcl' , 'tcl8.6' ),
191+ ]
192+ for alt_path in alternative_paths :
193+ if os .path .exists (alt_path ):
194+ os .environ ["TCL_LIBRARY" ] = alt_path
195+ break
196+
137197 # Create new root window
138198 temp_root = tk .Tk ()
139199 temp_root .withdraw () # Hide the main window
@@ -168,6 +228,9 @@ def root_function():
168228 "$DISPLAY environment variable" ,
169229 "application has been destroyed" ,
170230 "invalid command name \" tcl_findLibrary\" " ,
231+ "couldn't read file" ,
232+ "Tcl wasn't installed properly" ,
233+ "Tcl initialization" ,
171234 ]
172235 ):
173236 pytest .skip (
@@ -184,6 +247,35 @@ def root_isolated():
184247 try :
185248 # Set environment variables
186249 os .environ ["TK_SILENCE_DEPRECATION" ] = "1"
250+
251+ # Ensure DISPLAY is set for headless environments
252+ if "DISPLAY" not in os .environ :
253+ os .environ ["DISPLAY" ] = ":0.0"
254+
255+ # Set TCL_LIBRARY environment variable to help with Tcl initialization
256+ import sys
257+ if hasattr (sys , 'frozen' ):
258+ # Running as compiled executable
259+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
260+ else :
261+ # Running as script
262+ tcl_dir = os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' )
263+
264+ # Try to find Tcl library directory
265+ if os .path .exists (tcl_dir ):
266+ os .environ ["TCL_LIBRARY" ] = tcl_dir
267+ else :
268+ # Try alternative paths
269+ alternative_paths = [
270+ os .path .join (os .path .dirname (sys .executable ), 'tcl' , 'tcl8.6' ),
271+ os .path .join (os .path .dirname (sys .executable ), '..' , 'tcl' , 'tcl8.6' ),
272+ os .path .join (os .path .dirname (sys .executable ), '..' , '..' , 'tcl' , 'tcl8.6' ),
273+ ]
274+ for alt_path in alternative_paths :
275+ if os .path .exists (alt_path ):
276+ os .environ ["TCL_LIBRARY" ] = alt_path
277+ break
278+
187279 # Create new root window
188280 temp_root = tk .Tk ()
189281 temp_root .withdraw () # Hide the main window
@@ -228,6 +320,9 @@ def root_isolated():
228320 "$DISPLAY environment variable" ,
229321 "application has been destroyed" ,
230322 "invalid command name \" tcl_findLibrary\" " ,
323+ "couldn't read file" ,
324+ "Tcl wasn't installed properly" ,
325+ "Tcl initialization" ,
231326 ]
232327 ):
233328 pytest .skip (
@@ -694,6 +789,10 @@ def pytest_configure(config): # pylint: disable=unused-argument
694789
695790def pytest_collection_modifyitems (config , items ): # pylint: disable=unused-argument
696791 """Modify test collection for better parallel execution."""
792+ # Sort items to run GUI tests after non-GUI tests to avoid mock conflicts
793+ gui_items = []
794+ non_gui_items = []
795+
697796 for item in items : # pylint: disable=redefined-outer-name
698797 # Add gui marker to GUI tests
699798 if any (
@@ -703,6 +802,12 @@ def pytest_collection_modifyitems(config, items): # pylint: disable=unused-argu
703802 "pathbrowser" ,
704803 "pathchooser" ]):
705804 item .add_marker (pytest .mark .gui )
805+ gui_items .append (item )
806+ else :
807+ non_gui_items .append (item )
808+
809+ # Reorder items: non-GUI tests first, then GUI tests
810+ items [:] = non_gui_items + gui_items
706811
707812
708813# Common mock settings for PathBrowser
0 commit comments