Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1079656?usp=email )

Change subject: [test] run gui_tests with pytest and pytest-xvfb
......................................................................

[test] run gui_tests with pytest and pytest-xvfb

Also remove PYWIKIBOT_TEST_GUI environment variable.

Bug: T377065
Change-Id: Ibee9b624cb21158870b04c446846c890f07e33b8
---
M .github/workflows/pywikibot-ci.yml
M dev-requirements.txt
M tests/README.rst
M tests/gui_tests.py
4 files changed, 24 insertions(+), 18 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved
  jenkins-bot: Verified




diff --git a/.github/workflows/pywikibot-ci.yml 
b/.github/workflows/pywikibot-ci.yml
index 7e05b1f..5119a15 100644
--- a/.github/workflows/pywikibot-ci.yml
+++ b/.github/workflows/pywikibot-ci.yml
@@ -14,7 +14,6 @@
 env:
   PYWIKIBOT_TEST_RUNNING: 1
   PYWIKIBOT_USERNAME: Pywikibot-test
-  PYWIKIBOT_TEST_GUI: 1

 jobs:
   build:
@@ -74,9 +73,6 @@
       with:
         python-version: ${{ matrix.python-version }}

-    - name: Install Tkinter for Ubuntu
-      run: sudo apt-get install python3-tk
-
     - name: Install dependencies
       run: |
         python -m pip install --upgrade pip
@@ -127,7 +123,7 @@
           ${{ (matrix.site == 'wikisource:zh' || matrix.test_no_rc) && 1 || 0 
}}
       run: |
         python pwb.py version
-        if [ ${{matrix.site || 0}} != 'wikipedia:test' ]; then
+        if [ ${{matrix.site || 0}} != 'wikisource:zh' ]; then
           coverage run -m unittest discover -vv -p \"*_tests.py\";
         else
           pytest --cov=.;
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 87e1c4a..a87313f 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -6,6 +6,7 @@
 pytest-cov >= 2.11.1; python_version<"3.10"
 pytest-subtests >= 0.3.2
 pytest-attrib>=0.1.3
+pytest-xvfb>=3.0.0

 pre-commit
 coverage>=5.2.1
diff --git a/tests/README.rst b/tests/README.rst
index 94f8dfe..53a0784 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -81,13 +81,6 @@
 Environment variables
 =====================

-**PYWIKIBOT_TEST_GUI**
-  Enable :source:`tests/gui_tests`. Used for AppVeyor tests. GitHub actions 
would
-  fail due to ``couldn't connect to display ":1.0"`` error. Set this 
environment
-  variable to run this test locally::
-
-    PYWIKIBOT_TEST_GUI=1
-
 **PYWIKIBOT_TEST_LOGOUT**
   Used when a test is logging out the test user. This environment variable
   enables :source:`tests/site_login_logout_tests`. The environment setting is
@@ -174,6 +167,9 @@

     pwb PYWIKIBOT_TEST_WRITE script_tests -v TestScriptSimulate.test_archivebot

+.. versionremoved:: 9.5
+   The :envvar:`PYWIKIBOT_TEST_GUI` environment variable.
+
 Decorators
 ==========

diff --git a/tests/gui_tests.py b/tests/gui_tests.py
index b1602af..f6c51a4 100755
--- a/tests/gui_tests.py
+++ b/tests/gui_tests.py
@@ -1,13 +1,14 @@
 #!/usr/bin/env python3
 """Tests for the Tk UI."""
 #
-# (C) Pywikibot team, 2008-2023
+# (C) Pywikibot team, 2008-2024
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import annotations

 import os
+import sys
 import unittest
 from contextlib import suppress

@@ -59,12 +60,24 @@
 def setUpModule():
     """Skip tests if tkinter or PIL is not installed.

-    Also skip test if ``PYWIKIBOT_TEST_GUI`` environment variable is not
-    set. Otherwise import modules and run tests.
+    .. versionchanged:: 7.7
+       skip test if ``PYWIKIBOT_TEST_GUI`` environment variable is not
+       set.
+    .. versionchanged:: 9.5
+       :envvar:`PYWIKIBOT_TEST_GUI` environment variable was removed.
+       ``pytest`` with ``pytest-xvfb `` extension is required for this
+       tests on github actions.
     """
-    if os.environ.get('PYWIKIBOT_TEST_GUI', '0') != '1':
-        raise unittest.SkipTest('Tkinter tests are not enabled. '
-                                '(set PYWIKIBOT_TEST_GUI=1 to enable)')
+    if os.environ.get('GITHUB_ACTIONS'):
+        skip = True
+        if 'pytest' in sys.modules:
+            with suppress(ModuleNotFoundError):
+                import pytest_xvfb  # noqa: F401
+                skip = False
+
+        if skip:
+            raise unittest.SkipTest('Tkinter tests must run with pytest and '
+                                    'needs pytest-xvfb extension')

     global EditBoxWindow, Tkdialog, tkinter


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1079656?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ibee9b624cb21158870b04c446846c890f07e33b8
Gerrit-Change-Number: 1079656
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <i...@gno.de>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org
To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org

Reply via email to