Q: 使用运行testsuite时未定义全局名称py.tes公司

2024-05-14 06:57:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个unittest套件,通过ssh(使用paramiko)验证多个远程服务器的配置设置是否正常运行。我想使用pytest输出将它集成到Jenkins中,但是testsuite运行时py.测试给出以下错误:

名称错误:未定义全局名称''u ssh'

$ py.test --junitxml results.xml bsr-multinode.py -v -x
======= test session starts ===============
platform linux2 -- Python 2.7.11+, pytest-2.9.1, py-1.4.31, pluggy-0.3.1 -- /usr/bin/python
cachedir: .cache
rootdir: /home/dany, inifile: pytest.ini
collected 150 items 

bsr-multinode.py::myClass::test_test1 FAILED

------ generated xml file: /home/dany/results.xml ---------------
============ FAILURES ======================
__  myClass.test_test1 __________________________

self = <bsr-multinode.myClass testMethod=test_test1>

    def test_test1(self):
>       self.assertRegexpMatches(_ssh.execute('netstat -nlp | grep -vi unix | grep sshd'),'sshd','sshd not running')
E       NameError: global name '_ssh' is not defined

bsr-multinode.py:121: NameError
!!! Interrupted: stopping after 1 failures !!!!!!!
============= 1 failed in 0.50 seconds ====

$ python bsr-multinode.py 
ms-100-00
.......F..FFF.F.F.F.F.F.....F..F...
Ran 150 tests in 49.724s

FAILED (failures=35)
db-100-01
.......F..FFF.F.F.F.F.F.....F..F...
Ran 150 tests in 56.816s

FAILED (failures=56)

我在没有帮助的情况下尝试了不同的方法。任何线索都欢迎。这是我的代码:

^{pr2}$

Tags: inpytestselfpytest错误myclassxml

热门问题