验证python mock_请求库中的身份验证

验证python mock_请求库中的身份验证,python,unit-testing,requests-mock,Python,Unit Testing,Requests Mock,我正在创建一个单元测试,以确保我的http客户端正确地传递身份验证令牌。我正在使用请求\u mock库 with requests_mock.mock() as m: m.get( "https://my-endpoint", text="{}", ) history = m.request_history[0] assert "Bearer test" == history._request.headers.get("Authorization"

我正在创建一个单元测试,以确保我的http客户端正确地传递身份验证令牌。我正在使用请求\u mock

with requests_mock.mock() as m:
    m.get(
        "https://my-endpoint",
        text="{}",
    )
history = m.request_history[0]
assert "Bearer test" == history._request.headers.get("Authorization")

但是history.\u请求是受保护的成员,因此我希望避免在代码中绑定到受保护的成员。是否有更合适的方法来检查请求中的授权头\u mock

而不是使用
历史记录。\u request.headers
,您可以使用
历史记录.headers

例如:

导入请求
导入请求\u mock
将请求\u mock.mock()作为m:
m、 得到(
"https://my-endpoint",
text=“{}”,
)
头文件={'Authorization':'Bearer test'}
请求。获取('https://my-endpoint,headers=headers)
历史记录=m.request_历史记录[0]
断言“承载测试”==history.headers.get(“授权”)