使用pytest和tox,运行测试,并基于该测试,依次运行测试

时间:2019-10-23 11:37:07

标签: pytest tox

我编写了一些要使用pytest -n 10(tox编写的命令)并行运行的测试,这些测试正在使用某些进程。我已经编写了一个测试来检查这些进程是否正在运行。我想先运行此测试,然后再并行运行其他测试。简而言之,我想进行测试。如果使用pytest通过了该测试,则我想并行运行一些测试。如果该测试失败。执行应该停止。我正在使用tox和pytest。我想把这些条件写成毒药。 并且还可以通过任何方式依次和并行地进行一些测试。

    from io import StringIO
import fabric,re



fd = StringIO()
conn=fabric.Connection(ip, port=22, user="root", connect_kwargs={'password': password})
conn.get("/opt/CDOT-scscf/etc/scscf_defined_constants.cam","/tmp/scscf_conf.txt")
f=open("/tmp/scscf_conf.txt","r")
for i in f.readlines():
  if "IMS_PCSCF_ADDR "  in i :
    pcscf_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_ICSCF_ADDR "  in i :
    icscf_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_SCSCF_ADDR "  in i :
    scscf_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_AS_ADDR "  in i :
    tas_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_MRF_ADDR "  in i :
    mrf_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_DRA_ADDR "  in i :
    dra_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "IMS_SCSCF_ADDR_PORT" in i:
    scscf_port=re.findall(r'\d+',i)[0]
  if "IMS_PCSCF_ADDR_PORT" in i:
    pcscf_port=re.findall(r'\d+',i)[0]
  if "IMS_TAS_ADDR_PORT" in i:
    _port=re.findall(r'\d+',i)[0]
  if "IMS_ICSCF_ADDR_PORT" in i:
    scscf_port=re.findall(r'\d+',i)[0]
  if "IMS_MRF_ADDR_PORT" in i:
    scscf_port=re.findall(r'\d+',i)[0]
    dra_port=3868
conn.get("/opt/CDOT-dra/etc/diam_constants.cam","/tmp/dra_conf.txt")
f=open("/tmp/dra_conf.txt","r")
for i in f.readlines():
  if "DIAM_CDF_ADDR_1"  in i :
    cdf_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]
  if "DIAM_CDF_LCL_PORT_1" in i:
    cdf_port=re.findall(r'\d+',i)[1]
  if "DIAM_HSS_LCL_PORT_1" in i:
    hss_port=re.findall(r'\d+',i)[1]
  if "DIAM_HSS_ADDR_1 "  in i :
    hss_ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}',i)[0]

def netstat():
 return conn.run("netstat -apn| grep cdotdra",hide=True).stdout

def test_ims_status():
  a=netstat()
  assert dra_ip in a,"DRA IS NOT RUNNING"
  assert icscf_ip in a,"ICSCF IS NOT RUNNING"
  assert pcscf_ip in a,"PCSCF IS NOT RUNNING"
  assert scscf_ip in a,"SCSCF IS NOT RUNNING"
  assert tas_ip in a,"TAS IS NOT RUNNING"
  assert hss_ip in a,"HSS IS NOT RUNNING"
  assert mrf_ip in a,"MRF IS NOT RUNNING"
  assert cdf_ip in a,"CDF IS NOT RUNNING"


Above is the test file tests_ims_status.py which I want to run at starting, which will be failed if any of the server is not running.

这是我的tox.ini

 [tox]
envlist =  py37

[testenv]
deps =
    pytest
    sysrsync
    pytest-xdist
    pytest-html
    pandas
    xlrd
whitelist_externals=echo
list_dependencies_command=echo

commands =
#    pytest -s {posargs}
     pytest -n 2 -v -s --html=C5.html --self-contained-html --disable-pytest-warnings tests/*

因此,上面是tox.ini文件,它并行运行所有测试。我想要的是先运行test_ims_status。如果通过。然后并行运行所有测试。如果失败,请不要再进行任何测试。对于语法错误,我感到非常抱歉。如果您需要任何其他许可,请询问。

0 个答案:

没有答案
相关问题