访问特拉维斯-CI上的剪贴板



我正在尝试对我的应用程序运行(集成?(测试,以验证它是否确实使用pyperclip将预期的字符串复制到剪贴板。

这部分在我的开发机器(Windows 10(上工作;但在travis-ci上失败,我在travis作业日志中得到以下内容。

self = <pyperclip.init_no_clipboard.<locals>.ClipboardUnavailable object at 0x7ff0cd743588>
args = ('7 809823 102890 string 291',), kwargs = {}
def __call__(self, *args, **kwargs):
>       raise PyperclipException(EXCEPT_MSG)
E       pyperclip.PyperclipException: 
E           Pyperclip could not find a copy/paste mechanism for your system.
E           For more information, please visit https://pyperclip.readthedocs.io/en/latest/introduction.html#not-implemented-error
../../../virtualenv/python3.7.1/lib/python3.7/site-packages/pyperclip/__init__.py:301: PyperclipException

根据pyperclip文档,当没有复制/粘贴机制时,这种情况发生在Linux上。解决方案是安装以下之一(引用pyperclip文档(:

  • sudo apt-get install xsel安装 XSEL 实用程序。
  • sudo apt-get install xclip安装 xclip 实用程序。
  • pip install gtk安装 gtk Python 模块。
  • pip install PyQt4安装 PyQt4 Python 模块。

所以在我的.travis.yml文件中,我有

before_install:
- sudo apt-get install xclip

我也尝试过xsel,结果相同。

由于 travis 上的系统是 Ubuntu 16.04.6,我尝试将sudo apt-get install python3-pyperclip添加到before_install键中,结果相同。

我无法通过将gtkPyQt4添加到.travis.yml中的install密钥来安装它们。

install:
- pip install -r requirements_dev.txt
- pip install PyQt4
# or
- pip install gtk

由于这些都会导致以下错误:

Could not find a version that satisfies the requirement gtk (from versions: )
No matching distribution found for gtk
The command "pip install gtk" failed and exited with 1 during .

至此,我的before_install如下所示:

- sudo apt-get install xclip
- sudo apt-get install xsel
- sudo apt-get install python3-pyperclip
- sudo apt-get install gtk2.0

这似乎是矫枉过正(并且仍然不起作用(;但我目前对如何使该测试通过一无所知。任何指示将不胜感激。

谢谢

>xclip需要X服务器运行,而Travis机器以无头模式运行。您需要在虚拟帧缓冲区中运行该命令;除了xclip之外,还要安装xvfb并使用xvfb-run pytest而不是pytest。完整配置示例:

language: python
addons:
apt:
packages:
- xclip
- xvfb
python:
- "3.7"
# setup installation
install:
- pip install -r requirements_dev.txt
script: xvfb-run pytest

下面是一个基于 Travis 构建的示例。请注意,我使用addons来声明应该与 APT 一起安装的依赖项;在before_install部分中显式安装它们的解决方案也是完全有效的,只是品味问题。

最新更新