import sys from pathlib import Path import pytest @pytest.fixture def temp_package(tmp_path: Path): """ Creates a temporary Python package and adds it to sys.path. """ pkg = tmp_path / "testpkg" pkg.mkdir() (pkg / "__init__.py").write_text('"""Test package."""\n') sys.path.insert(0, str(tmp_path)) yield pkg sys.path.remove(str(tmp_path))