我有以下几点。
@pytest.fixture
def patch_socket(monkeypatch):
def gethostname():
return 'web01-east.domain.com'
monkeypatch.setattr(socket, 'gethostname', gethostname)
def test__get_pod(patch_socket):
assert __get_pod() == 'east'如果我想测试以下主机名,正确的方法是什么?
我应该为每个测试设置一个新的夹具,还是有一种方法可以在测试本身中传递主机名?
发布于 2015-01-12 09:54:02
使用此代码
@pytest.fixture(params=['web01-east.domain.com', 'redis01-master-east.domain.com', 'web01.domain.com'])
def patch_socket(request, monkeypatch):
def gethostname():
return request.param
monkeypatch.setattr(socket, 'gethostname', gethostname)
def test__get_pod(patch_socket):
assert __get_pod() == 'east'这将创建3个动态测试。如果您使用-vv运行,您将看到如下内容:
<FILE>::test__get_pod[web01-east.domain.comm PASSED
<FILE>::test__get_pod[redis01-master-east.domain.com] PASSED
<FILE>::test__get_pod[web01.domain.com PASSEDhttps://stackoverflow.com/questions/27895880
复制相似问题