mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Add support for pytest fixtures from local pytest plugins.
This commit is contained in:
@@ -181,6 +181,9 @@ def _iter_pytest_modules(module_context, skip_own_module=False):
|
||||
if Path(file_io.path) != module_context.py__file__():
|
||||
try:
|
||||
m = load_module_from_path(module_context.inference_state, file_io)
|
||||
pytest_plugins_pointer = m.goto("pytest_plugins")
|
||||
if pytest_plugins_pointer:
|
||||
yield from _load_pytest_plugins(module_context, pytest_plugins_pointer[0])
|
||||
yield m.as_context()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
@@ -196,6 +199,17 @@ def _iter_pytest_modules(module_context, skip_own_module=False):
|
||||
yield module_value.as_context()
|
||||
|
||||
|
||||
def _load_pytest_plugins(module_context, plugins_pointers):
|
||||
from jedi.inference.value import iterable
|
||||
from parso.python.tree import String
|
||||
for inferred in plugins_pointers.infer():
|
||||
if isinstance(inferred, iterable.SequenceLiteralValue):
|
||||
for value in inferred.get_tree_entries():
|
||||
if isinstance(value, String):
|
||||
for module_value in module_context.inference_state.import_module(eval(value.value).split(".")):
|
||||
yield module_value.as_context()
|
||||
|
||||
|
||||
class FixtureFilter(ParserTreeFilter):
|
||||
def _filter(self, names):
|
||||
for name in super()._filter(names):
|
||||
|
||||
@@ -27,3 +27,9 @@ def capsysbinary(capsysbinary):
|
||||
#? ['close']
|
||||
capsysbinary.clos
|
||||
return capsysbinary
|
||||
|
||||
|
||||
# used when fixtures are defined in multiple files
|
||||
pytest_plugins = [
|
||||
"completion.fixture_module",
|
||||
]
|
||||
|
||||
6
test/completion/fixture_module.py
Normal file
6
test/completion/fixture_module.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# Exists only for completion/pytest.py
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def my_module_fixture():
|
||||
return 1.0
|
||||
@@ -96,6 +96,9 @@ def test_x(my_con
|
||||
#? 18 ['my_conftest_fixture']
|
||||
def test_x(my_conftest_fixture):
|
||||
return
|
||||
#? ['my_module_fixture']
|
||||
def test_x(my_modu
|
||||
return
|
||||
|
||||
#? []
|
||||
def lala(my_con
|
||||
|
||||
Reference in New Issue
Block a user