jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/831091 )
Change subject: [tests] create DISPLAY environment variable to run tkinter tests ......................................................................
[tests] create DISPLAY environment variable to run tkinter tests
Change-Id: I912d9a5ad72231033c1fb6fddcfd773b359ec74f --- M tests/tk_tests.py 1 file changed, 25 insertions(+), 5 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/tk_tests.py b/tests/tk_tests.py index 58a283d..f94dffd 100755 --- a/tests/tk_tests.py +++ b/tests/tk_tests.py @@ -5,6 +5,7 @@ # # Distributed under the terms of the MIT license. # +import os import unittest from contextlib import suppress
@@ -12,12 +13,33 @@ from tests.aspects import DefaultSiteTestCase, TestCase, require_modules
-class TestTkdialog(TestCase): +class TkinterTestsBase(TestCase):
- """Test Tkdialog.""" + """TestCase base for Tkinter tests."""
net = True
+ @classmethod + def setUpClass(cls): + """Set virtual display environment.""" + super().setUpClass() + cls.env = os.environ.get('DISPLAY') + os.environ['DISPLAY'] = ':0.0' + + @classmethod + def tearDownClass(cls): + """Restore the display environment value.""" + if not cls.env: + del os.environ['DISPLAY'] + else: + os.environ['DISPLAY'] = cls.env + super().tearDownClass() + + +class TestTkdialog(TkinterTestsBase): + + """Test Tkdialog.""" + def testTkdialog(self): """Test Tk dialog.""" try: @@ -27,12 +49,10 @@ pywikibot.warning(e)
-class TestTkinter(DefaultSiteTestCase): +class TestTkinter(TkinterTestsBase, DefaultSiteTestCase):
"""Test Tkinter."""
- net = True - def testTkinter(self): """Test Tkinter window.""" root = tkinter.Tk()
pywikibot-commits@lists.wikimedia.org