我正在尝试编写一个测试来通过有效和无效的代理详细信息。我已经编写了一个pytestfixture,它将执行请求并返回响应。但我的问题是,我想在fixture期间发送无效和有效的代理详细信息。有人能纠正我这个方法是否正确或建议我的有效方法,我是新的Pytests。我试过以下方法
@pytest.fixture(scope="module")
@pytest.mark.parametrize("proxyDict",[
({
"http": "web-proxy.testsite:8080",
"https": "web-proxy.testsite:8080"
}),
({
"http": "web-wrong:8080",
"https": "web-.wrong:8080"
})
])
def cve_response(proxy_dict):
year="2018"
base_url = 'https://static.nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-' + str(year) + '.json.zip'
headers = {
"content-type": "application/json"
}
response_data = requests.request("GET", base_url, headers=headers, verify=False, stream=True,
proxies=proxy_dict)
yield response_data
@pytest.mark.proxy
def test_valid_proxy(cve_response):
assert 200 == cve_response.status_code
@pytest.mark.invalidproxy
def test_invalid_proxy(cve_response):
assert not 200 == cve_response.status_code
您需要参数化测试用例,而不是夹具。而且,这不是使用固定装置的用例。所以,你应该这样处理:
相关问题 更多 >
编程相关推荐