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

Change --runtime flag to accept comma-separated list of runtimes #76

Merged
merged 10 commits into from
Dec 15, 2022
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
override `selenium_standalone` fixture with `selenium_standalone_refresh`.
[#65](https://github.com/pyodide/pytest-pyodide/pull/65)

- Breaking: `--runtime` commandline flag now requires runtimes to be comma-separated.
[#76](https://github.com/pyodide/pytest-pyodide/pull/76)

- Add support for a custom `SimpleHTTPRequestHandler` class in the pytest
webserver code, by passing the `handler_cls` parameter in the
`spawn_web_server` function.
Expand Down
13 changes: 7 additions & 6 deletions pytest_pyodide/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
RUNTIMES_NO_HOST = [f"{runtime}-no-host" for runtime in RUNTIMES]


def _filter_runtimes(runtime: list[str]) -> tuple[bool, set[str]]:
def _filter_runtimes(runtime: str) -> tuple[bool, set[str]]:
# Always run host test, unless 'no-host' is given.
ryanking13 marked this conversation as resolved.
Show resolved Hide resolved
run_host = True

# "chrome, firefox, node" ==> ["chrome", "firefox", "node"]
runtimes = [rt.strip() for rt in runtime.split(",")]

# remove duplicates
runtime_set = set(runtime)
runtime_set = set(runtimes)

runtime_filtered = set()
for rt in runtime_set:
Expand Down Expand Up @@ -89,10 +92,8 @@ def pytest_addoption(parser):
"--rt",
"--runtime",
dest="runtime",
nargs="+",
default=["node"],
choices=RUNTIMES_AND_HOST + RUNTIMES_NO_HOST,
ryanking13 marked this conversation as resolved.
Show resolved Hide resolved
help="Select runtime (default: %(default)s)",
default="node",
help="Select runtimes to run tests (default: %(default)s)",
)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ def test_option(request):
"firefox",
"safari",
"node",
"firefox chrome",
"firefox,chrome",
],
)
def test_runtime(pytester, _runtime):

runtimes = _runtime.split()
runtimes = _runtime.split(",")

pytester.makepyfile(
f"""
import pytest
def test_option(request):
assert request.config.getoption("--runtime") == {runtimes!r}
def test_option():
assert pytest.pyodide_runtimes == set({runtimes!r})
"""
)

result = pytester.runpytest("--runtime", *runtimes)
result = pytester.runpytest("--runtime", _runtime)
result.assert_outcomes(passed=1)