有没有办法通过在主站上运行的示例来检测某个作业)以检查下一个构建步骤所需的从站是否在线?
如果并非所有需要的从属节点都在线,我希望主作业失败并且不启动任何下一个构建.
问题与标题一样,如何通过示例模拟 select.select 以测试我的线程运行功能。测试功能失败
ready = select.select([self.sock], [], [], 5)
TypeError: fileno() returned a non-integer
Run Code Online (Sandbox Code Playgroud)
和类型打印给出
输入'builtin_function_or_method'
所以很明显 select.select 在线程的范围内没有被模拟,而在测试中它是......(assert isinstance)
import select
import threading
RECEIVE_BYTES = 256
class Bar(threading.Thread):
def __init__(self, sock):
threading.Thread.__init__(self)
self.sock = sock
def run(self):
print type(select.select)
ready = select.select([self.sock],[],[],5)
if ready[0]:
print self.sock.recv(RECEIVE_BYTES)
Run Code Online (Sandbox Code Playgroud)
在另一个模块中测试如下
def test_run(self):
with patch("select.select"):
select.select.return_value = [True]
mock_sock = MagicMock()
foo = Bar(mock_sock)
assert isinstance(select.select, MagicMock)
foo.start()
Run Code Online (Sandbox Code Playgroud)
测试通过鼻子运行
python unit-testing mocking python-multithreading python-2.7
我有一个测试类,我的所有测试都继承自该类。它无法自行运行,因为它实际上不包含任何设置信息
我想添加一个由所有测试执行的测试(将其添加到基类似乎合乎逻辑)
但现在我注意到我导入的 basetestclass( => Foo) 被检测为测试本身并运行并在报告中可见
base.py 中的基类
from unittest import TestCase
class Foo(TestCase):
@classmethod
def setUpClass(cls):
# prepare the generic setup stuff based on what is defined in the child class
print("setupclass Foo done")
def test_run_in_all_inherited_tests(self):
print("fooBar")
assert True
Run Code Online (Sandbox Code Playgroud)
真正的测试在 test_something.py
from base import Foo # <= This is being detected as a testclass object and thus will be executed
class TestFoo(Foo):
@classmethod
def setUpClass(cls):
# define specific test setup
super().setUpClass()
print("setup TestFoo done")
def test_pass(self): …Run Code Online (Sandbox Code Playgroud) python ×2
inheritance ×1
jenkins ×1
mocking ×1
nose ×1
pytest ×1
python-2.7 ×1
unit-testing ×1