Skip to content
Merged
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
29 changes: 10 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,25 @@ def test_x(install_test_package):
package_path = pathlib.Path(info["path"]).resolve()
if not package_path.exists():
raise FileNotFoundError(f"Package path not found: {package_path}")

if package_path is None:
raise RuntimeError(f"No package_path defined for install_test_package fixture")

if not ((package_path / "pyproject.toml").exists() or (package_path / "setup.py").exists()):
raise RuntimeError(f"No pyproject.toml or setup.py found in {package_path}")
raise RuntimeError(f"No pyproject.toml or setup.py found in {package_path}")

# Install package
# Install package in a classis way, `--editable` create a .pth entry in conda env which is imcompatible with submodule
if package_path is not None:
subprocess.check_call([
sys.executable, "-m", "pip", "install", "--quiet", "--editable", str(package_path)
sys.executable, "-m", "pip", "--quiet", "install", str(package_path)
])
else:
subprocess.check_call([
sys.executable, "-m", "pip", "install", "--quiet", "--editable", str(package_name)
])
# Test the import.
import importlib
# Ensure its path is importable
if str(package_path) not in sys.path:
sys.path.insert(0, str(package_path))

# Remove from sys.modules to avoid caching issues
sys.modules.pop(package_name, None)

yield package_name

# Uninstall package
subprocess.call([
sys.executable, "-m", "pip", "uninstall", "-y", package_name
])
# Do not uninstall package at the end to speed up tests a bit
#subprocess.call([
# sys.executable, "-m", "pip", "uninstall", "-y", package_name
#])


@pytest.fixture
Expand Down
Loading