mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Fix fixture annotations for pytest
This means mostly these: @fixture def foo() -> Generator[int, None, None]: ...
This commit is contained in:
@@ -31,7 +31,15 @@ def execute(callback):
|
|||||||
def infer_anonymous_param(func):
|
def infer_anonymous_param(func):
|
||||||
def get_returns(value):
|
def get_returns(value):
|
||||||
if value.tree_node.annotation is not None:
|
if value.tree_node.annotation is not None:
|
||||||
return value.execute_with_values()
|
result = value.execute_with_values()
|
||||||
|
if any(v.name.get_qualified_names(include_module_names=True)
|
||||||
|
== ('typing', 'Generator')
|
||||||
|
for v in result):
|
||||||
|
return ValueSet.from_sets(
|
||||||
|
v.py__getattribute__('__next__').execute_annotation()
|
||||||
|
for v in result
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
# In pytest we need to differentiate between generators and normal
|
# In pytest we need to differentiate between generators and normal
|
||||||
# returns.
|
# returns.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
@@ -169,3 +171,15 @@ def test_inheritance_fixture(inheritance_fixture, caplog):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def caplog(caplog):
|
def caplog(caplog):
|
||||||
yield caplog
|
yield caplog
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# Generator with annotation
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def with_annot() -> Generator[float, None, None]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_with_annot(inheritance_fixture, with_annot):
|
||||||
|
#? float()
|
||||||
|
with_annot
|
||||||
|
|||||||
Reference in New Issue
Block a user