PS D:\a\b\PythonProject1> pytest
========================================================================= test session starts =========================================================================
platform win32 -- Python 3.11.9, pytest-8.4.1, pluggy-1.6.0
rootdir: D:\a\b\PythonProject1
configfile: pytest.ini
testpaths: test_test/
plugins: html-4.1.1, metadata-3.1.1, parallel-0.1.1, repeat-0.9.4, testreport-1.1.6, xdist-3.8.0
collected 3 items
test_test\test_api.py .FF [100%]
============================================================================== FAILURES ===============================================================================
________________________________________________________ TestLogin.test_login_module[api_info0-testcase0-2-3] _________________________________________________________
self = <test_test.test_api.TestLogin object at 0x0000014DF0970690>
api_info = {'api_name': '用户登录', 'headers': {'Content-Type': 'application/x-www-form-urlencoded'}, 'method': 'post', 'url': 'https://10.121.177.71/itf/session', ...}
testcase = {'data': {'password': 'admin', 'username': 'admin'}}
@pytest.mark.passdef
@pytest.mark.repeat(3)
@pytest.mark.parametrize('api_info,testcase', YamlUtil().read_def_yaml('get_new.yaml'))
def test_login_module(self, api_info, testcase):
if 'case_name' not in testcase:
testcase['case_name'] = f"默认用例_{id(testcase)}" # 用唯一标识避免重复
> RequestsBase().execute_test_cases(api_info, testcase)
test_test\test_api.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
unit_tools\apiutils_single.py:121: in execute_test_cases
raise e
unit_tools\apiutils_single.py:117: in execute_test_cases
self.asserts.assert_result(validation,response.json(),status_code)
unit_tools\assertion_utils.py:125: in assert_result
raise exceptions
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'unit_tools.assertion_utils.Assertions'>, expected_result = None
response = {'CSRFToken': '6d4IxqO2', 'ChangePasswordAlert': 0, 'CommConfigPriv': 1, 'DebugPriv': 1, ...}, status_code = 200
@classmethod
def assert_result(cls, expected_result, response, status_code):
"""
断言主函数,通过all_flag标记,如all_flag == 0表示测试成功,否则为失败
:param expected_result: (list)yaml文件validation关键词下面的预期结果
:param response: (dict)接口的实际响应信息
:param status_code: (int)接口的实际响应状态码
:return:
"""
all_flag = 0
# 通过字典映射方式管理不同的断言方式
assert_methods = {
'code': cls.status_code_assert,
'contain': cls.contain_assert,
'eq': cls.equal_assert
# 'ne': cls.not_equal_assert,
}
try:
> for yq in expected_result:
E TypeError: 'NoneType' object is not iterable
unit_tools\assertion_utils.py:110: TypeError
------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------
请求头参数: {'Content-Type': 'application/x-www-form-urlencoded'}
参数类型:data
请求参数:{"username": "admin", "password": "admin"}
接口返回值: { "ResidueDay": 255, "ok": 0, "privilege": 4, "user_id": 2, "extendedpriv": 383, "racsession_id": 8, "remote_addr": "10.121.178.218", "server_name": "10.12
1.177.71", "server_addr": "10.121.177.71", "HTTPSEnabled": 1, "CSRFToken": "6d4IxqO2", "channel": 1, "passwordStatus": 0, "encrypt_flag": 0, "SelfSetPriv": 1, "InfoQuer
yPriv": 1, "DebugPriv": 1, "PowerConPriv": 1, "SecuConPriv": 1, "RemoteMediaPriv": 1, "RemoteKVMPriv": 1, "CommConfigPriv": 1, "UserConfigPriv": 1, "group_name": "Administrator", "ChangePasswordAlert": 0 }
出现异常,--'NoneType' object is not iterable
________________________________________________________ TestLogin.test_login_module[api_info0-testcase0-3-3] _________________________________________________________
self = <test_test.test_api.TestLogin object at 0x0000014DF320E050>
api_info = {'api_name': '用户登录', 'headers': {'Content-Type': 'application/x-www-form-urlencoded'}, 'method': 'post', 'url': 'https://10.121.177.71/itf/session', ...}
testcase = {'data': {'password': 'admin', 'username': 'admin'}}
@pytest.mark.passdef
@pytest.mark.repeat(3)
@pytest.mark.parametrize('api_info,testcase', YamlUtil().read_def_yaml('get_new.yaml'))
def test_login_module(self, api_info, testcase):
if 'case_name' not in testcase:
testcase['case_name'] = f"默认用例_{id(testcase)}" # 用唯一标识避免重复
> RequestsBase().execute_test_cases(api_info, testcase)
test_test\test_api.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
unit_tools\apiutils_single.py:121: in execute_test_cases
raise e
unit_tools\apiutils_single.py:117: in execute_test_cases
self.asserts.assert_result(validation,response.json(),status_code)
unit_tools\assertion_utils.py:125: in assert_result
raise exceptions
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'unit_tools.assertion_utils.Assertions'>, expected_result = None
response = {'CSRFToken': 'Su8wXUR2', 'ChangePasswordAlert': 0, 'CommConfigPriv': 1, 'DebugPriv': 1, ...}, status_code = 200
@classmethod
def assert_result(cls, expected_result, response, status_code):
"""
断言主函数,通过all_flag标记,如all_flag == 0表示测试成功,否则为失败
:param expected_result: (list)yaml文件validation关键词下面的预期结果
:param response: (dict)接口的实际响应信息
:param status_code: (int)接口的实际响应状态码
:return:
"""
all_flag = 0
# 通过字典映射方式管理不同的断言方式
assert_methods = {
'code': cls.status_code_assert,
'contain': cls.contain_assert,
'eq': cls.equal_assert
# 'ne': cls.not_equal_assert,
}
try:
> for yq in expected_result:
E TypeError: 'NoneType' object is not iterable
unit_tools\assertion_utils.py:110: TypeError
------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------
请求头参数: {'Content-Type': 'application/x-www-form-urlencoded'}
参数类型:data
请求参数:{"username": "admin", "password": "admin"}
接口返回值: { "ResidueDay": 255, "ok": 0, "privilege": 4, "user_id": 2, "extendedpriv": 383, "racsession_id": 9, "remote_addr": "10.121.178.218", "server_name": "10.12
1.177.71", "server_addr": "10.121.177.71", "HTTPSEnabled": 1, "CSRFToken": "Su8wXUR2", "channel": 1, "passwordStatus": 0, "encrypt_flag": 0, "SelfSetPriv": 1, "InfoQuer
yPriv": 1, "DebugPriv": 1, "PowerConPriv": 1, "SecuConPriv": 1, "RemoteMediaPriv": 1, "RemoteKVMPriv": 1, "CommConfigPriv": 1, "UserConfigPriv": 1, "group_name": "Administrator", "ChangePasswordAlert": 0 }
出现异常,--'NoneType' object is not iterable
========================================================================== warnings summary ===========================================================================
test_test/test_api.py::TestLogin::test_login_module[api_info0-testcase0-1-3]
test_test/test_api.py::TestLogin::test_login_module[api_info0-testcase0-2-3]
test_test/test_api.py::TestLogin::test_login_module[api_info0-testcase0-3-3]
D:\python\Lib\site-packages\urllib3\connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host '10.121.177.71'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================= short test summary info =======================================================================
FAILED test_test/test_api.py::TestLogin::test_login_module[api_info0-testcase0-2-3] - TypeError: 'NoneType' object is not iterable
FAILED test_test/test_api.py::TestLogin::test_login_module[api_info0-testcase0-3-3] - TypeError: 'NoneType' object is not iterable
最新发布