【发布时间】:2022-11-17 10:03:50
【问题描述】:
我一直在研究 fastAPI 并有一些异步方法来生成授权令牌
编写单元测试时出现以下错误:
TypeError: test_get_auth_token() missing 2 required positional arguments: 'test_input' and 'expected_result'
我的单元测试看起来像:
class TestGenerateAuthToken(IsolatedAsyncioTestCase):
"""
"""
@pytest.mark.parametrize(
"test_input,expected_result",
[("user", "user_token"), ("admin", "admin_token")],
)
@mock.patch("myaauth.get_token", new_callable=AsyncMock)
async def test_get_auth_token(self, get_token_mock, test_input, expected_result):
"""
Test get_auth_header
"""
def mock_generate_user_token(_type):
return f"{_type}_token"
get_token_mock.side_effect = mock_generate_user_token
assert await myaauth.get_token(test_input) == expected_result
我知道就像删除参数一样简单,但我想知道是否可以这样做
【问题讨论】:
标签: python python-3.x unit-testing pytest