gpt4 book ai didi

python - 在 Travis-CI 上访问剪贴板

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:58 24 4
gpt4 key购买 nike

我正尝试在我的 application 上运行(集成?)测试, 以验证它确实使用 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 documentation ,当没有复制/粘贴机制时,这会发生在 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,我尝试在before_install键中加入sudo apt-get install python3-pyperclip,结果一样。

我无法通过将它们添加到 .travis.yml< 中的 install 键来安装 gtkPyQt4/.

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 机器以 headless 模式运行。您需要在虚拟帧缓冲区中运行该命令;除了 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

这是一个例子 build on Travis .请注意,我使用 addons 来声明应该使用 APT 安装的依赖项;您在 before_install 部分显式安装它们的解决方案也完全有效,只是个人喜好问题。

关于python - 在 Travis-CI 上访问剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57743427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com