Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate tests that uses external_fixturepkg into a venv #783

Merged
merged 5 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# **Upcoming release**

- #781, #783 Isolate tests that uses external_fixturepkg into a venv
- #751 Check for ast.Attributes when finding occurrences in fstrings (@sandratsy)
- #777, #698 add validation to refuse Rename refactoring to a python keyword (@lieryan)
- #730 Match on module aliases for autoimport suggestions (@MrBago)
Expand Down
57 changes: 51 additions & 6 deletions ropetest/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
import os
import pathlib
import sys
from subprocess import check_call
from venv import EnvBuilder

import pytest

from rope.base import resources
from ropetest import testutils


@pytest.fixture(scope="session")
def session_venv(tmpdir_factory):
path = tmpdir_factory.mktemp("venv")
venv_path = pathlib.Path(path)

builder = EnvBuilder(with_pip=True)
builder.create(venv_path)

yield venv_path


@pytest.fixture(scope="session")
def session_venv_pyvenv_cfg(session_venv):
cfg = session_venv / "pyvenv.cfg"
return dict(line.split(" = ") for line in cfg.read_text().splitlines())


@pytest.fixture(scope="session")
def session_venv_site_packages(session_venv, session_venv_pyvenv_cfg):
if os.name == 'nt':
return session_venv / f"Lib/site-packages"

Check warning on line 33 in ropetest/conftest.py

View check run for this annotation

Codecov / codecov/patch

ropetest/conftest.py#L33

Added line #L33 was not covered by tests
else:
major, minor, patch = session_venv_pyvenv_cfg["version"].split(".")
return session_venv / f"lib/python{major}.{minor}/site-packages"


@pytest.fixture(scope='session')
def session_venv_python_executable(session_venv):
# Get the path to the Python executable inside the venv
if os.name == 'nt':
python_executable = session_venv / 'Scripts' / 'python.exe'

Check warning on line 43 in ropetest/conftest.py

View check run for this annotation

Codecov / codecov/patch

ropetest/conftest.py#L43

Added line #L43 was not covered by tests
else:
python_executable = session_venv / 'bin' / 'python'

# Yield the Python executable path
yield python_executable


@pytest.fixture
def project():
project = testutils.sample_project()
def project(session_venv, session_venv_site_packages):
project = testutils.sample_project(
python_path=[str(session_venv_site_packages)],
)
yield project
testutils.remove_project(project)

Expand All @@ -21,8 +63,11 @@


@pytest.fixture
def project2():
project = testutils.sample_project("sample_project2")
def project2(session_venv):
project = testutils.sample_project(
"sample_project2",
python_path=[str(session_venv_site_packages)],
)
yield project
testutils.remove_project(project)

Expand Down Expand Up @@ -50,9 +95,9 @@


@pytest.fixture(scope="session")
def external_fixturepkg():
def external_fixturepkg(session_venv, session_venv_python_executable):
check_call([
sys.executable,
session_venv_python_executable,
"-m",
"pip",
"install",
Expand Down
29 changes: 16 additions & 13 deletions ropetest/contrib/autoimport/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,41 @@
@pytest.fixture
def mod1(project):
mod1 = testutils.create_module(project, "mod1")
yield mod1
return mod1


@pytest.fixture
def mod1_path(mod1):
yield pathlib.Path(mod1.real_path)
return pathlib.Path(mod1.real_path)


@pytest.fixture
def typing_path():
import typing

yield pathlib.Path(typing.__file__)
return pathlib.Path(typing.__file__)


@pytest.fixture
def example_external_package_module_path(external_fixturepkg):
from external_fixturepkg import mod1
yield pathlib.Path(mod1.__file__)
def example_external_package_module_path(
session_venv,
external_fixturepkg,
session_venv_site_packages,
):
return session_venv_site_packages / "external_fixturepkg/mod1.py"


@pytest.fixture
def example_external_package_path(external_fixturepkg):
import external_fixturepkg

# Uses __init__.py so we need the parent

yield pathlib.Path(external_fixturepkg.__file__).parent
def example_external_package_path(
session_venv,
external_fixturepkg,
session_venv_site_packages,
):
return session_venv_site_packages / "external_fixturepkg"


@pytest.fixture
def compiled_lib():
import _sqlite3

yield "_sqlite3", pathlib.Path(_sqlite3.__file__)
return "_sqlite3", pathlib.Path(_sqlite3.__file__)
3 changes: 1 addition & 2 deletions ropetest/contrib/autoimporttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ def test_skipping_directories_not_accessible_because_of_permission_error(self):
self.assertGreater(len(self.importer._dump_all()), 0)


def test_search_submodule(external_fixturepkg):
project = testutils.sample_project(extension_modules=["sys"])
def test_search_submodule(project, external_fixturepkg):
importer = autoimport.AutoImport(project, observe=False)
importer.update_module("external_fixturepkg")
import_statement = ("from external_fixturepkg import mod1", "mod1")
Expand Down
Loading