Skip to content

Commit

Permalink
Run tests with local micropip (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 authored Oct 31, 2022
1 parent ed1efa0 commit 8c164d2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- uses: codecov/codecov-action@v3
if: ${{ github.event.repo.name == 'pyodide/micropip' || github.event_name == 'pull_request' }}
with:
fail_ci_if_error: true
fail_ci_if_error: false

deploy:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ __pycache__
micropip/_version.py
*.egg-info
dist/
build/
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ dependencies = []
[project.optional-dependencies]
test = [
"pytest-pyodide",
"pytest-cov"
"pytest-cov",
"build",
]


Expand All @@ -28,7 +29,7 @@ test = [


[build-system]
requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2"]
requires = ["setuptools>=42", "setuptools_scm[toml]>=6.2", "wheel"]

build-backend = "setuptools.build_meta"

Expand Down
45 changes: 38 additions & 7 deletions tests/test_micropip.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,48 @@ def mock_fetch(monkeypatch, mock_importlib, wheel_base):
return result


@pytest.fixture(scope="module")
def wheel_path(tmp_path_factory):
# Build a micropip wheel for testing
import build
from build.env import IsolatedEnvBuilder

output_dir = tmp_path_factory.mktemp("wheel")

with IsolatedEnvBuilder() as env:
builder = build.ProjectBuilder(Path(__file__).parent.parent)
builder.python_executable = env.executable
builder.scripts_dir = env.scripts_dir
env.install(builder.build_system_requires)
builder.build("wheel", output_directory=output_dir)

yield output_dir


@pytest.fixture
def selenium_standalone_micropip(selenium_standalone):
def selenium_standalone_micropip(selenium_standalone, wheel_path):
"""Import micropip before entering test so that global initialization of
micropip doesn't count towards hiwire refcount.
"""
selenium_standalone.run_js(
"""
await pyodide.loadPackage("micropip");
pyodide.runPython("import micropip");
"""
)

wheel_dir = Path(wheel_path)
wheel_files = list(wheel_dir.glob("*.whl"))

if not wheel_files:
pytest.exit("No wheel files found in wheel/ directory")

wheel_file = wheel_files[0]
with spawn_web_server(wheel_dir) as server:
server_hostname, server_port, _ = server
base_url = f"http://{server_hostname}:{server_port}/"
selenium_standalone.run_js(
f"""
await pyodide.loadPackage("{base_url + wheel_file.name}");
await pyodide.loadPackage(["packaging", "pyparsing"]);
pyodide.runPython("import micropip");
"""
)

yield selenium_standalone


Expand Down

0 comments on commit 8c164d2

Please sign in to comment.