From 184f2938d6d9b219454d3efe729e055fd8521269 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Wed, 17 Feb 2021 21:01:22 +0000
Subject: [PATCH] TEST: Adjust idle unit test

---
 tests/test_idle.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tests/test_idle.py b/tests/test_idle.py
index e6615319..edf0ecb1 100644
--- a/tests/test_idle.py
+++ b/tests/test_idle.py
@@ -38,6 +38,11 @@ def _run_with_wx(func, *args, **kwargs):
     if callAfterApp is not None:
         callAfterApp()
 
+    # canHaveGui caches its return val,
+    # so clear it otherwise we may
+    # affect subsequent tests
+    idle._canHaveGui.cache_clear()
+
     def wrap():
 
         try:
@@ -64,6 +69,8 @@ def _run_with_wx(func, *args, **kwargs):
 
     idle.idleLoop.reset()
 
+    idle._canHaveGui.cache_clear()
+
     if raised[0] and propagateRaise:
         raise raised[0]
 
@@ -413,10 +420,9 @@ def test_idle_alwaysQueue4():
     import fsl.utils.platform
     with mock.patch.dict('sys.modules', {'wx' : None}):
 
-        # idle uses the platform module to
-        # determine whether a GUI is available,
-        # so we have to reload it
-        reload_module(fsl.utils.platform)
+        # The idle._canHaveGui caches its result,
+        # so we need to invalidate it
+        idle._canHaveGui.cache_clear()
         idle.idle(task, alwaysQueue=True)
 
         with pytest.raises(ImportError):
-- 
GitLab