Fix a bug that prevented some Xvfb processes from ending

This commit is contained in:
Michael Mintz 2023-02-17 21:55:30 -05:00
parent b023adf685
commit b6e6c7dd0b
3 changed files with 55 additions and 53 deletions

View File

@ -173,6 +173,7 @@ class BaseCase(unittest.TestCase):
self._chart_first_series = {}
self._chart_series_count = {}
self._tour_steps = {}
self._xvfb_display = None
@classmethod
def main(self, name, file, *args):
@ -12721,8 +12722,9 @@ class BaseCase(unittest.TestCase):
try:
from sbvirtualdisplay import Display
self.display = Display(visible=0, size=(width, height))
self.display.start()
self._xvfb_display = Display(visible=0, size=(width, height))
self._xvfb_display.start()
sb_config._virtual_display = self._xvfb_display
self.headless_active = True
sb_config.headless_active = True
except Exception:
@ -14833,15 +14835,6 @@ class BaseCase(unittest.TestCase):
self.__activate_debug_mode_in_teardown()
# (Pytest) Finally close all open browser windows
self.__quit_all_drivers()
if self.headless or self.headless2 or self.xvfb:
if self.headless_active:
try:
self.display.stop()
except AttributeError:
pass
except Exception:
pass
self.display = None
if self.with_db_reporting:
if has_exception:
self.__insert_test_result(constants.State.FAILED, True)
@ -14924,15 +14917,6 @@ class BaseCase(unittest.TestCase):
print(msg)
if self.dashboard:
self.__process_dashboard(has_exception)
if self.headless or self.headless2 or self.xvfb:
if self.headless_active:
try:
self.display.stop()
except AttributeError:
pass
except Exception:
pass
self.display = None
if has_exception:
test_id = self.__get_test_id()
test_logpath = os.path.join(self.log_path, test_id)
@ -14987,6 +14971,16 @@ class BaseCase(unittest.TestCase):
# (Nosetests / Behave / Pure Python) Close all open browser windows
self.__quit_all_drivers()
# Resume tearDown() for all test runners, (Pytest / Nosetests / Behave)
if hasattr(self, "_xvfb_display") and self._xvfb_display:
try:
if hasattr(self._xvfb_display, "stop"):
self._xvfb_display.stop()
self._xvfb_display = None
self.headless_active = False
except AttributeError:
pass
except Exception:
pass
if self.__visual_baseline_copies:
sb_config._visual_baseline_copies = True
if has_exception:

View File

@ -1825,24 +1825,22 @@ def pytest_runtest_teardown(item):
except Exception:
pass
try:
if hasattr(self, "xvfb") and self.xvfb:
if self.headless_active and "--pdb" not in sys_argv:
if hasattr(self, "display") and self.display:
self.headless_active = False
sb_config.headless_active = False
self.display.stop()
elif hasattr(self, "headless") and self.headless:
if self.headless_active and "--pdb" not in sys_argv:
if hasattr(self, "display") and self.display:
self.headless_active = False
sb_config.headless_active = False
self.display.stop()
elif hasattr(self, "headless2") and self.headless2:
if self.headless_active and "--pdb" not in sys_argv:
if hasattr(self, "display") and self.display:
self.headless_active = False
sb_config.headless_active = False
self.display.stop()
if (
hasattr(self, "_xvfb_display")
and self._xvfb_display
and hasattr(self._xvfb_display, "stop")
):
self.headless_active = False
sb_config.headless_active = False
self._xvfb_display.stop()
self._xvfb_display = None
if (
hasattr(sb_config, "_virtual_display")
and sb_config._virtual_display
and hasattr(sb_config._virtual_display, "stop")
):
sb_config._virtual_display.stop()
sb_config._virtual_display = None
except Exception:
pass
except Exception:

View File

@ -1123,9 +1123,6 @@ class SeleniumBrowser(Plugin):
# (Set --server="127.0.0.1" for localhost Grid)
if str(self.options.port) == "443":
test.test.protocol = "https"
if self.options.xvfb and "linux" not in sys.platform:
# The Xvfb virtual display server is for Linux OS Only!
self.options.xvfb = False
if (
"linux" in sys.platform
and not self.options.headed
@ -1171,6 +1168,9 @@ class SeleniumBrowser(Plugin):
if not self.options.headless and not self.options.headless2:
self.options.headed = True
test.test.headed = True
sb_config._virtual_display = None
sb_config.headless_active = False
self.headless_active = False
if (
self.options.headless
or self.options.headless2
@ -1180,8 +1180,9 @@ class SeleniumBrowser(Plugin):
# from pyvirtualdisplay import Display # Skip for own lib
from sbvirtualdisplay import Display
self.display = Display(visible=0, size=(1440, 1880))
self.display.start()
self._xvfb_display = Display(visible=0, size=(1440, 1880))
self._xvfb_display.start()
sb_config._virtual_display = self._xvfb_display
self.headless_active = True
sb_config.headless_active = True
except Exception:
@ -1213,13 +1214,22 @@ class SeleniumBrowser(Plugin):
pass
except Exception:
pass
if self.options.headless or self.options.xvfb:
if self.headless_active:
try:
self.headless_active = False
sb_config.headless_active = False
self.display.stop()
except AttributeError:
pass
except Exception:
pass
try:
if (
hasattr(self, "_xvfb_display")
and self._xvfb_display
and hasattr(self._xvfb_display, "stop")
):
self.headless_active = False
sb_config.headless_active = False
self._xvfb_display.stop()
self._xvfb_display = None
if (
hasattr(sb_config, "_virtual_display")
and sb_config._virtual_display
and hasattr(sb_config._virtual_display, "stop")
):
sb_config._virtual_display.stop()
sb_config._virtual_display = None
except Exception:
pass