首页 > 其他分享 >pytest some

pytest some

时间:2023-03-07 23:02:03浏览次数:32  
标签:stdout self some pytest command ssh password port

import paramiko
import time
import allure
from self import self
import pytest


class SSLConnection:

    def run(self, ssh, command):
        stdin, stdout, stderr = ssh.exec_command(command)
        result = stdout.read().decode()
        # print(result)
        return result

    def shutdown(self, ssh):
        ssh.close()

    def connectSSL(self, hostname, port, username, password):
        # 创建SSH对象
        ssh = paramiko.SSHClient()

        # 允许连接不在know_hosts文件中的主机,否则可能报错:paramiko.ssh_exception.SSHException: Server '192.168.43.140' not found in known_hosts
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        # 连接服务器
        ssh.connect(hostname=hostname, port=port, username=username, password=password)
        # 执行命令
        # stdin:标准输入(就是你输入的命令);stdout:标准输出(就是命令执行结果);stderr:标准错误(命令执行过程中如果出错了就把错误打到这里),stdout和stderr仅会输出一个
        # print(command)
        return ssh
        # stdin, stdout, stderr = ssh.exec_command(command)

        # 获取命令结果
        # result = stdout.read().decode()  # 这个有问题,不显示错误,可以修改一下,先判断stdout有没有值,如果输出没有,就显示错误
        # print(result)
        # return result
        # 关闭连接
        # ssh.close()


@allure.feature("ceshi")
def test_compare():
    hostname = '192.168.60.129'
    port = '22'
    username = 'root'
    password = '1'
    command = [u'sudo uptime',
               'date +%s', 'ifconfig']
    ssh = SSLConnection.connectSSL(self, hostname=hostname, port=port, username=username, password=password)
    for i in range(0, len(command)):
        res = SSLConnection.run(self, ssh=ssh, command=command[i])
        print(res)
    SSLConnection.shutdown(self, ssh=ssh)


if __name__ == '__main__':
    test_compare()

 

标签:stdout,self,some,pytest,command,ssh,password,port
From: https://www.cnblogs.com/luobomao/p/17190066.html

相关文章

  • pytest - 结合 allure 报告
    修改报告内fixture方法名展示@allure.title("我是fixture")defsetup_session(autouse=True,scope="session")print("setup")yieldprint("teardown")......
  • (原创)【B4A】一步一步入门06:Button,背景图片、渐变、圆角、FontAwesome(控件篇02)
    一、前言本篇教程,我们来讲一下最常用的控件:Button(按钮)。本篇教程将会讲解按钮的文本样式、背景样式,以及诸如FontAwesome、圆角等如何设置。相信看完的你,一定会有所收获!......
  • pytest-笔记
    pytest的固件   模块级别   类级别   函数级别   方法级别setup_module(),teardown_module():(模块级别)一前一后,必须写成声明的函数,不能加self,可以实现整个......
  • Git推送提示: failed to push some refs to xxxxxxxx.git
    Git推送消息提示:failedtopushsomerefstoxxxxxxxx.git 原因:远程库与本地库代码不一致导致解决方案:方法一:同步远程库数据到本地库后在提交gitpull--rebase......
  • pytest-断言语句
    pytest允许在测试用例中使用标准的python断言,如下:#test_case.py中的内容deffoo(x,y):returnx+ydeftest_01():assertfoo(3,4)==8本例中的函数期望返......
  • pytest 的命令行执行 ;jenkins命令行执行
    命令行执行#!/bin/bashcd/home/autoTest/yi_api_test_profess/test_casepython3-mpytest-vstest_order_profess.py-mcn--alluredir/root/.jenkins/workspace/yi......
  • Pytest之生成allure报告
    一、前戏在之前我们已经学会使用pytest-html插件生成html格式的测试报告:1#第一步,安装插件2pipinstallpytest-html3​4#第二步,执行用例时使用--html......
  • Pytest 固件
    一、固件使用背景在执行测试用例时,我们常常需要在测试用例执行的前后去完成一些额外的操作。例如针对于Web测试,在用例执行前需要打开浏览器,完成用户登录等一系列前置操......
  • pytest-依赖测试
    背景我们在接口自动化过程中,总会存在依赖性较强的场景,比如批价->下单->支付,具备强依赖关系,这个时候就用到了依赖测试。参考https://blog.csdn.net/dingding_ting/artic......
  • Hadoop&Spark-Lec-Something-New
    NarrowandWideTransformationsNarrowtransformation:Asingleoutputpartitioncanbecomputedfromasingleinputpartition不需要考虑数据分区eg.filter(),......