asweigart / pyperclip

Python module for cross-platform clipboard functions.
https://pypi.python.org/pypi/pyperclip
BSD 3-Clause "New" or "Revised" License
1.6k stars 193 forks source link

Tests are broken in 1.9.0 release #263

Open mgorny opened 2 weeks ago

mgorny commented 2 weeks ago
$ tox -e py310
.pkg: install_requires> python -I -m pip install 'setuptools>=40.8.0' wheel
.pkg: _optional_hooks> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: install_requires_for_build_wheel> python -I -m pip install wheel
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py310: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/pyperclip/.tox/.tmp/package/1/pyperclip-1.9.0.tar.gz
py310: commands[0]> python tests/test_pyperclip.py
Traceback (most recent call last):
  File "/tmp/pyperclip/tests/test_pyperclip.py", line 11, in <module>
    from pyperclip import _executable_exists, HAS_DISPLAY
ImportError: cannot import name 'HAS_DISPLAY' from 'pyperclip' (/tmp/pyperclip/.tox/py310/lib/python3.10/site-packages/pyperclip/__init__.py)
py310: exit 1 (0.05 seconds) /tmp/pyperclip> python tests/test_pyperclip.py pid=68651
  py310: FAIL code 1 (5.28=setup[5.23]+cmd[0.05] seconds)
  evaluation failed :( (5.46 seconds)

…and indeed, there is no HAS_DISPLAY in it anymore.

mtelka commented 2 weeks ago

With the HAS_DISPLAY removed:

--- pyperclip-1.9.0/tests/test_pyperclip.py.orig
+++ pyperclip-1.9.0/tests/test_pyperclip.py
@@ -8,7 +8,7 @@
 #import sys
 #sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

-from pyperclip import _executable_exists, HAS_DISPLAY
+from pyperclip import _executable_exists
 from pyperclip import (init_osx_pbcopy_clipboard, init_osx_pyobjc_clipboard,
                                   init_dev_clipboard_clipboard,
                                   init_qt_clipboard,
@@ -134,16 +134,6 @@
             clipboard = init_osx_pyobjc_clipboard()

-class TestQt(_TestClipboard):
-    if HAS_DISPLAY:
-        try:
-            import PyQt5.QtWidgets
-        except ImportError:
-            pass
-        else:
-            clipboard = init_qt_clipboard()
-
-
 class TestXClip(_TestClipboard):
     if _executable_exists("xclip"):
         clipboard = init_xclip_clipboard()

I see following two test failures:

FAIL: test_non_str (__main__.TestXClip)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "$(BUILD_DIR)/tests/test_pyperclip.py", line 104, in test_non_str
    self.copy(None)
AssertionError: PyperclipException not raised

======================================================================
FAIL: test_non_str (__main__.TestXSel)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "$(BUILD_DIR)/tests/test_pyperclip.py", line 104, in test_non_str
    self.copy(None)
AssertionError: PyperclipException not raised
musicinmybrain commented 2 weeks ago

I was looking at updating python-pyperclip in Fedora, and I followed exactly the same process – noticing that pyperclip.HAS_DISPLAY was removed but the tests were not adapted, devising and testing the patch in https://github.com/asweigart/pyperclip/issues/263#issuecomment-2178394553, and encountering AssertionError: PyperclipException not raised test failures (I also see the failure on tests/test_pyperclip.py::TestQt::test_non_str).