Skip to content

Commit

Permalink
LayoutsTest : Don't pollute tests with gui configs
Browse files Browse the repository at this point in the history
Run the test in a subprocess instead so that we're leaving things as we found them.
  • Loading branch information
johnhaddon committed Jun 26, 2023
1 parent 00095c1 commit 6dfee3e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions python/GafferUITest/LayoutsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
##########################################################################

import os
import subprocess

import Gaffer
import GafferUI
Expand Down Expand Up @@ -84,19 +85,28 @@ def testPersistence( self ) :

def testNoPersistentLayoutsInDefaultConfigs( self ) :

if "GAFFERUITEST_LAYOUTTEST_SUBPROCESS" not in os.environ :
# Run test in subprocess, because we don't want to pollute the other
# tests with the configs we load.
try :
env = os.environ.copy()
env["GAFFERUITEST_LAYOUTTEST_SUBPROCESS"] = "1"
subprocess.check_output(
[ str( Gaffer.executablePath() ), "test", "GafferUITest.LayoutsTest.testNoPersistentLayoutsInDefaultConfigs" ],
stderr = subprocess.STDOUT,
env = env,
)
except subprocess.CalledProcessError as e :
self.fail( e.output )
return

app = Gaffer.Application()

# Load the GUI config, making sure we only use the standard
# startup files, and not any others from the current environment
# (the user running these tests may have their own personal configs).
startupPaths = os.environ["GAFFER_STARTUP_PATHS"]
try :
os.environ["GAFFER_STARTUP_PATHS"] = str( Gaffer.rootPath() / "startup" )
app._executeStartupFiles( "gui" )
finally :
os.environ["GAFFER_STARTUP_PATHS"] = startupPaths

self.assertEqual( os.environ["GAFFER_STARTUP_PATHS"], startupPaths )
os.environ["GAFFER_STARTUP_PATHS"] = str( Gaffer.rootPath() / "startup" )
app._executeStartupFiles( "gui" )

layouts = GafferUI.Layouts.acquire( app )
self.assertEqual( layouts.names( persistent = True ), [] )
Expand Down

0 comments on commit 6dfee3e

Please sign in to comment.