Skip to content

Commit

Permalink
[test] run gui_tests with pytest and pytest-xvfb
Browse files Browse the repository at this point in the history
Also remove PYWIKIBOT_TEST_GUI environment variable.

Bug: T377065
Change-Id: Ibee9b624cb21158870b04c446846c890f07e33b8
  • Loading branch information
xqt committed Oct 13, 2024
1 parent d732e08 commit c7fb9ac
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/pywikibot-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ concurrency:
env:
PYWIKIBOT_TEST_RUNNING: 1
PYWIKIBOT_USERNAME: Pywikibot-test
PYWIKIBOT_TEST_GUI: 1

jobs:
build:
Expand Down Expand Up @@ -74,9 +73,6 @@ jobs:
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
Expand Down Expand Up @@ -127,7 +123,7 @@ jobs:
${{ (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=.;
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pytest-cov >= 3.0.0; python_version>="3.10"
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
Expand Down
10 changes: 3 additions & 7 deletions tests/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ With -lang and -family or -site options pwb can be used to specify a site.
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
Expand Down Expand Up @@ -174,6 +167,9 @@ The assignment can be omitted and defaults to 1. The following is equal to the l

pwb PYWIKIBOT_TEST_WRITE script_tests -v TestScriptSimulate.test_archivebot

.. versionremoved:: 9.5
The :envvar:`PYWIKIBOT_TEST_GUI` environment variable.

Decorators
==========

Expand Down
25 changes: 19 additions & 6 deletions tests/gui_tests.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -59,12 +60,24 @@ def test_tkinter(self):
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

Expand Down

0 comments on commit c7fb9ac

Please sign in to comment.