How to setup a remote python test framework for LabVIEW

  • Software
  1. python with package:
    pyriott (pip install pyriott -i http://ni-pypi --trusted-host ni-pypi) - Master/slave
    mobilize (pip install mobilize -i http://ni-pypi --trusted-host ni-pypi) -Master/Slave
    rpyc (pip install rpyc) - Master/Slave
    Mobilize (???) - Master

在用mobilize时,测试环境上需要安装
‘machinations’,
‘mobilize’,
‘pytest’,
‘pytest_origin_reporter’,
‘pyyaml’,
‘pyriott’

Master:

(venv) C:\Users\zhyang\Desktop\switch_test>pip freeze
attrs==19.3.0
cattrs==0.9.0
enum34==1.1.6
labview-automation==19.0.7
plumbum==1.6.7
psutil==5.6.3
pymongo==3.9.0
pyriott==19.0.2
rpyc==4.1.2
six==1.12.0

Slave:

attrs==19.3.0
cattrs==0.9.0
enum34==1.1.6
labview-automation==19.0.7
plumbum==1.6.7
psutil==5.6.3
pymongo==3.9.0
pyriott==19.0.2
rpyc==4.1.2
six==1.12.0
virtualenv==16.7.5

How to install virtual enviroment:

pip install virtualenv
mkdir myproject
cd myproject
virtualenv --no-site-packages venv
venv/Scripts/activate

ref:https://www.liaoxuefeng.com/wiki/1016959663602400/1019273143120480

  1. Python scripte:
    Master:
import os
import shutil
import socket
import re
import rpyc

from labview_automation.client import LabVIEWClient
from pyriott.deploy_and_run import DeployAndRun


Slave_addr = '10.144.160.204'
Lvproj_path = r'C:\switch_test\Switch RT test.lvproj'
VI_path = r'C:\switch_test\connectTest.vi'
Target_type = 'RT PXI Target'
LabVIEW_version = '2019'

def run():
    conn = rpyc.classic.connect(Slave_addr)
    conn._config['sync_request_timeout'] = 60
    lv_utilities = conn.modules['labview_automation.labview.utilities']
    lv_utilities.start_labview_server(LabVIEW_version, True, True)

    indicators = ['Pass', 'error out', 'Result Paragraphs']
    with LabVIEWClient(Slave_addr) as lvClient:
        result = DeployAndRun(lvClient).deploy_and_run_vi(
            Lvproj_path, Target_type, VI_path, Target_type,
            indicators_to_get=indicators, leave_vis_open=True)
        print("", result)

run()

Note:
Master和Slave上有相同的目录结构。venv路径 “C:\Users\zhyang\Desktop\cleanEnv\switch_test\venv…”
相同的库和VI “C:\Users\zhyang\Desktop\cleanEnv\switch_test\venv\Lib\site-packages\pyriott\vis\rt_deploy\Deploy and Run.vi”

  • 操作步骤
    Slave: cmd: python C:\Users\zhyang\AppData\Local\Programs\Python\Python37-32\Scripts\rpyc_classic.py --host 0.0.0.0 (0.0.0.0使所有人可以访问,127.0.0.1使自己可以访问)
    Master:
  1. cd switch_test\venv\Scripts ; >>activate

  2. cmd: (venv) C:\Users\zhyang\Desktop\switch_test>python test.py run
    {‘Pass’: True, ‘error out’: {‘status’: False, ‘code’: 0, ‘source’: ‘’}, ‘Result Paragraphs’: ‘Open\tClosed\tOpen’}

测试项目:
How to setup a remote python test framework for LabVIEW_第1张图片
How to setup a remote python test framework for LabVIEW_第2张图片
How to setup a remote python test framework for LabVIEW_第3张图片
Pass, Result Paragraphs, error out是必须控件。

你可能感兴趣的:(LabVIEW)