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

Add basic integration tests #164

Merged
merged 12 commits into from
Dec 7, 2024
42 changes: 41 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ concurrency:
jobs:
test:
runs-on: ${{ matrix.os }}
needs: [check-integration-test-trigger]
env:
DISPLAY: :99
strategy:
Expand Down Expand Up @@ -51,7 +52,20 @@ jobs:
- name: Run tests
shell: bash -l {0}
run: |
pytest -v \
pytest -v tests \
--cov=micropip \
--durations=10 \
--dist-dir=./dist/ \
--maxfail=15 \
--runner=${{ matrix.test-config.runner }} \
--rt ${{ matrix.test-config.runtime }}

- name: Run integration tests
if: needs.check-integration-test-trigger.outputs.run-integration-test
shell: bash -l {0}
run: |
pytest -v tests/integration \
--integration \
--cov=micropip \
--durations=10 \
--dist-dir=./dist/ \
Expand All @@ -64,6 +78,32 @@ jobs:
with:
fail_ci_if_error: false

check-integration-test-trigger:
name: test-integration-test-trigger
runs-on: ubuntu-latest
outputs:
run-integration-test: ${{ steps.check-integration-test-trigger.outputs.trigger }}

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}

- id: check-integration-test-trigger
name: Check integration test trigger
shell: bash
run: |
set -e -x

COMMIT_MSG=$(git log --no-merges -1 --oneline)

# The integration tests will be triggered on push or on pull_request when the commit
# message contains "[integration]" or if it is pushed to main branch.
if [[ "$GITHUB_EVENT_NAME" == push && "$GITHUB_REF" == refs/heads/main ||
"$COMMIT_MSG" =~ \[integration\] ]]; then
echo "trigger=true" >> "$GITHUB_OUTPUT"
fi

deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: "3.11"
python: "3.12"

exclude: (^micropip/externals|^tests/vendored|^tests/test_data)
repos:
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def pytest_addoption(parser):
help="Run tests that query remote package indexes.",
)

parser.addoption(
"--integration",
action="store_true",
default=None,
help="Run integration tests.",
)


EMSCRIPTEN_VER = "3.1.14"
PLATFORM = f"emscripten_{EMSCRIPTEN_VER.replace('.', '_')}_wasm32"
Expand Down
81 changes: 81 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# integration tests for micropip
# these test often requires querying to the real packages existing in PyPI,
ryanking13 marked this conversation as resolved.
Show resolved Hide resolved
# to test the micropip's ability to install packages from real world package indexes.

# To prevent sending many requests to remote servers, these tests are disabled by default.
# To run these tests locally, add `--integration` flag, when inovking pytest.
ryanking13 marked this conversation as resolved.
Show resolved Hide resolved

from pytest_pyodide import run_in_pyodide


def test_integration_install_basic(selenium_standalone_micropip, pytestconfig):
pytestconfig.getoption("--integration", skip=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a separate fixture or decorator for this so that we can say:

@integration_only
@run_in_pyodide
def test_integration_install_basic(selenium_standalone_micropip):
    # test body

Or maybe it would be possible to skip the entire file instead of each test individually?


@run_in_pyodide
async def _run(selenium):
import micropip

await micropip.install("snowballstemmer")

import snowballstemmer

snowballstemmer.stemmer("english")

_run(selenium_standalone_micropip)


def test_integration_list_basic(selenium_standalone_micropip, pytestconfig):
pytestconfig.getoption("--integration", skip=True)

@run_in_pyodide
async def _run(selenium):
import micropip

await micropip.install("snowballstemmer")

packages = micropip.list()
assert "snowballstemmer" in packages

_run(selenium_standalone_micropip)


def test_integration_uninstall_basic(selenium_standalone_micropip, pytestconfig):
pytestconfig.getoption("--integration", skip=True)

@run_in_pyodide
async def _run(selenium):
import micropip

await micropip.install("snowballstemmer")

import snowballstemmer

snowballstemmer.stemmer("english")

micropip.uninstall("snowballstemmer")

packages = await micropip.list()
assert "snowballstemmer" not in packages

_run(selenium_standalone_micropip)


def test_integration_freeze_basic(selenium_standalone_micropip, pytestconfig):
pytestconfig.getoption("--integration", skip=True)

@run_in_pyodide
async def _run(selenium):
import json

import micropip

await micropip.install("snowballstemmer")

import snowballstemmer

snowballstemmer.stemmer("english")

lockfile = micropip.freeze()
assert "snowballstemmer" in json.loads(lockfile)

_run(selenium_standalone_micropip)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file contains tests that actually query remote package indexes,
# to ensure that micropip works with real-world package indexes.
# Since running these tests will send many requests to remote servers,
# these tests are disabled by default.
# these tests are disabled by default in CI.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you said: "To run these tests locally, add --integration flag". Here you say they are disabled by default in CI. But aren't they are also disabled by default locally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, they are disabled both locally and CI by default. I'll update the wording

#
# To run these tests, add `--run-remote-index-tests` flag, or
# these tests can also be run in Github Actions manually.
Expand Down
Loading