Tom*_*ica 10 python fixtures pytest pylance
考虑以下代码:
fixtures.py
@pytest.fixture
def hello_world():
return "Hello world!"
Run Code Online (Sandbox Code Playgroud)
进而...
basic_tests.py
def test_says_hello(hello_world):
assert hello_world == "Hello world!"
Run Code Online (Sandbox Code Playgroud)
现在的问题是, pylance 无法知道 pytest 会hello_world用fixture 的返回值来填充我的参数hello_world()。对于像这样简单的事情str,这可以手动完成,但是当处理许多返回复杂值的装置时,这不仅对于编写代码不切实际,而且对于读取代码也是不切实际的。
有没有某种方法可以扩展 pytest 功能,以便每当遇到没有显式类型的参数时,都可以提供正确的类型?我可以编写提供类型的部分,但我什至不确定我可以改变 pylance 行为或如何做到这一点。