【问题标题】:Pytest blocks pyside code from executionPytest 阻止 pyside 代码执行
【发布时间】:2016-11-05 10:46:16
【问题描述】:

我有一个带有按钮、标签等的主窗口。

我有一个带有测试功能的示例脚本。

我有一个 pytest 夹具来获取当前执行的测试函数名称。

我想将当前的测试函数名称打印到主窗口中的标签上。


这是我获取测试函数名称的代码:

...
request.node.name

这是我在pyside中设置标签的代码

label_curr_test_name.setText(...)

我的代码看起来像这样:

testcase.py

def test_1(update_test_status):
    assert True
def test_2(update_test_status):
    assert True

conftest.py

import pytest
from testmain import MainWindow # my window with the label created with pyside

@pytest.fixture()
def update_test_status(request):
    # implemented as singleton
    main = MainWindow() 
    main.label_curr_test_name.setText(request.node.name)

这根本没有设置标签。还有一件重要的事情要知道:我有一个“开始”按钮,当单击时会启动 pytest:

testmain.py

 full_path = file_path + directory + file_name + '.py'
 pytest.main(['-x', full_path])

在该命令之后,对 pyside 设置标签的任何调用都会失败,而没有 pytest 运行它可以工作。

有人可以帮忙吗?是什么问题或如何解决?

【问题讨论】:

    标签: python user-interface pyside pytest


    【解决方案1】:

    解决了这个问题。问题是 pyside 在 1 个主线程中运行。此时运行的任何其他进程都会冻结 pyside。所以解决方案是在一个线程中单独调用 pytest。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      相关资源
      最近更新 更多