Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Windows主机在远程Linux计算机上运行部分Python单元测试_Python_Linux_Windows_Pytest_Xdist - Fatal编程技术网

从Windows主机在远程Linux计算机上运行部分Python单元测试

从Windows主机在远程Linux计算机上运行部分Python单元测试,python,linux,windows,pytest,xdist,Python,Linux,Windows,Pytest,Xdist,我的情况是这样的: 我有一个基于windows的服务器程序和一个基于linux的客户端 我对linux客户机进行了许多测试,这些客户机在本地linux机器上运行,并且需要在本地linux机器上运行 我需要从windows server机器上运行一些代码,这些代码将向linux客户端发送一些消息。然后,应在linux客户机上执行测试,以验证这些消息的效果 因此,在windows主机上运行的典型测试用例如下所示: test_example_message(self): # has to

我的情况是这样的:

  • 我有一个基于windows的服务器程序和一个基于linux的客户端
  • 我对linux客户机进行了许多测试,这些客户机在本地linux机器上运行,并且需要在本地linux机器上运行
  • 我需要从windows server机器上运行一些代码,这些代码将向linux客户端发送一些消息。然后,应在linux客户机上执行测试,以验证这些消息的效果
因此,在windows主机上运行的典型测试用例如下所示:

test_example_message(self):
    # has to be executed locally on windows server
    send_message(EXAMPLE, hosts)
    # has to be executed locally on linux clients
    for host in hosts:
        verify_message_effect(EXAMPLE, host)
我发现,pytest xdist以某种方式能够做到这一点


我是否有关于如何使用它的好教程或代码示例?

我的最终设计使用ssh和多处理而不是xdist(在execute_tc()函数中):


我认为您已经更改了执行测试用例的方法,以执行特定的测试用例。

到目前为止我找到的一些资源:;;;anothore one(捷克语):[horejsek.blog]()这看起来相当令人讨厌!我个人认为你应该在单元测试中嘲笑主持人之间的交流,但是如果你真的想这样做,你也可以在你的linux机器上使用
ssh@python execute\u-verification.py
简单地执行你的验证脚本,然后用
check\u-output
捕获这个脚本的输出,并在你的windows主机上验证返回值。@flazzarini是的,我最终决定编写我自己的“堆栈”,使用ssh在多个线程/进程中执行。(在我的例子中,并行化是至关重要的)。经过一些研究,我发现无论如何我都需要使用xdist(也就是说,编写远程执行堆栈)。好的,您可以在这里回答自己的问题。我发现这个示例在处理ssh时特别有用:我总是觉得分布式/ssh集成测试很有趣(并没有很好的文档记录或博客)。感谢您的更新。我使用SSH(Paramiko)来实现这一点。我正在测试一个大系统,太大而无法模拟,太大而无法“启动运行测试并销毁”。(我们没有模拟,我们有不断检查或回滚实验室到已知状态的脚本)。我使用Paramiko(SSH)来“在服务器A上执行操作,等待,然后检查服务器B上的状态(它使用来自A的下游数据)。如果我从零开始,我可能倾向于使用Spur.py而不是Paramiko。“函数”根据“平台”参数负责具体执行的操作。
def test_函数(result_dict,platform,[server,…):if platform='windows':result\u dict['windows']=do\u sth\u local()其他:result\u dict[platform]=ssh\u execute('remote\u func',server)
import multiprocessing
import test_functions

def test_example_message(self):
"""Example test case"""
    # to get IPs, usernames, passwords, other required data
    config = get_test_config('example_message')
    # will take care of threading and executing parts
    result_dict = execute_tc(config)
    # to fail or not to fail. take care of proper reporting
    process_results(result_dict)

def execute_tc(config):
"""Execute test code in parallel"""
    # create shared results dictionary
    manager = multiprocessing.Manager()
    result_dict = manager.dict({})
    # create processes
    processes = []
    for func, platform, args in config:
        function = getattr(test_functions, func)
        worker = multiprocessing.Process(target=function, args=[result_dict, platform, args])
        worker.daemon = True
        worker.start()
        processes.append(worker)

    for process in processes:
        process.join()

    return result_dict
def execute_tc(config):
"""Execute test code in parallel"""
    # create shared results dictionary
    manager = multiprocessing.Manager()
    result_dict = manager.dict({})
    # create processes
    processes = []
    for func, platform, args in config:
        function = getattr(test_functions, func)
        worker = multiprocessing.Process(target=function, args=[result_dict, platform, args])
        worker.daemon = True
        worker.start()
        processes.append(worker)

    for process in processes:
        process.join()

    return result_dict