admin 管理员组文章数量: 1086019
I want to write unit-tests for a Typer based CLI, that will run the CLI with different inputs and validate correct argument parsing and input validation. The point isn't to test Typer itself, but rather to test my code's integration with Typer.
In addition, my CLI has some logic which I would like to mock during these tests (for example, HTTP API calls). Obviously, I want to make sure that tests that check input validation don't run real API calls.
Here is a simplified version of how my code might look like, where DataFetcher
is some class defined elsewhere in the project:
import typer
app = typer.Typer()
@appmand()
def fetch_data(user_id: str):
with DataFetcher() as data_fetcher:
result = data_fetcher.fetch_data(user_id)
typer.echo(result)
if __name__ == "__main__":
app()
In this case, are there ways to explicitly mock DataFetcher (such as with the built-in mock
library?)
Ideally, I'd want to use explicit mocking rather than patching/monkeypatching.
本文标签: pythonUsing explicit mocks for Typer CLI testsStack Overflow
版权声明:本文标题:python - Using explicit mocks for Typer CLI tests - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744090735a2531984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论