mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Add tests to find pytest fixtures from external plugins
This commit is contained in:
@@ -183,3 +183,28 @@ def with_annot() -> Generator[float, None, None]:
|
|||||||
def test_with_annot(inheritance_fixture, with_annot):
|
def test_with_annot(inheritance_fixture, with_annot):
|
||||||
#? float()
|
#? float()
|
||||||
with_annot
|
with_annot
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# pytest external plugins
|
||||||
|
# -----------------
|
||||||
|
|
||||||
|
#? ['admin_user', 'admin_client']
|
||||||
|
def test_z(admin
|
||||||
|
|
||||||
|
#! 15 ['def admin_client']
|
||||||
|
def test_p(admin_client):
|
||||||
|
#? ['login', 'logout']
|
||||||
|
admin_client.log
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
@some_decorator
|
||||||
|
#? ['admin_user']
|
||||||
|
def bla(admin_u
|
||||||
|
return
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
@some_decorator
|
||||||
|
#! 12 ['def admin_user']
|
||||||
|
def bla(admin_user):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
|
||||||
|
@fixture()
|
||||||
|
def admin_user():
|
||||||
|
pass
|
||||||
18
test/examples/pytest_plugin_package/pytest_plugin/plugin.py
Normal file
18
test/examples/pytest_plugin_package/pytest_plugin/plugin.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import pytest
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
|
||||||
|
from pytest_plugin.fixtures import admin_user # noqa
|
||||||
|
|
||||||
|
|
||||||
|
class Client:
|
||||||
|
def login(self, **credentials):
|
||||||
|
...
|
||||||
|
|
||||||
|
def logout(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def admin_client():
|
||||||
|
return Client()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -42,6 +43,22 @@ def test_completion(case, monkeypatch, environment, has_django):
|
|||||||
|
|
||||||
if (not has_django) and case.path.endswith('django.py'):
|
if (not has_django) and case.path.endswith('django.py'):
|
||||||
pytest.skip('Needs django to be installed to run this test.')
|
pytest.skip('Needs django to be installed to run this test.')
|
||||||
|
|
||||||
|
if case.path.endswith("pytest.py"):
|
||||||
|
# to test finding pytest fixtures from external plugins
|
||||||
|
# add a stub pytest plugin to the project sys_path...
|
||||||
|
pytest_plugin_dir = str(helpers.get_example_dir("pytest_plugin_package"))
|
||||||
|
case._project.added_sys_path = [pytest_plugin_dir]
|
||||||
|
|
||||||
|
# ... and mock setuptools entry points to include it
|
||||||
|
# see https://docs.pytest.org/en/stable/how-to/writing_plugins.html#setuptools-entry-points
|
||||||
|
def mock_entry_points(group):
|
||||||
|
assert group == "pytest11"
|
||||||
|
EntryPoint = namedtuple("EntryPoint", ["value"])
|
||||||
|
return [EntryPoint(value="pytest_plugin.plugin")]
|
||||||
|
|
||||||
|
monkeypatch.setattr("jedi.plugins.pytest.entry_points", mock_entry_points)
|
||||||
|
|
||||||
repo_root = helpers.root_dir
|
repo_root = helpers.root_dir
|
||||||
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
monkeypatch.chdir(os.path.join(repo_root, 'jedi'))
|
||||||
case.run(assert_case_equal, environment)
|
case.run(assert_case_equal, environment)
|
||||||
|
|||||||
Reference in New Issue
Block a user