Skip to content

Commit b18ee17

Browse files
committed
run_in_pyodide: Add handling for when requested packages are not built
* When running outside of pytest, raise a RuntimeError * When running in pytest locally, skip the test * When running in pytest in CI, fail the test Can configure whether we want the test to be skipped or failed with the `skip_if_not_all_built` argument.
1 parent 1670627 commit b18ee17

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pytest_pyodide/decorator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ast
22
import functools
3+
import os
34
import pickle
45
import sys
56
from base64 import b64decode, b64encode
@@ -381,6 +382,7 @@ def __new__(cls, function: Callable | None = None, /, **kwargs):
381382
def __init__(
382383
self,
383384
packages: Collection[str] = (),
385+
skip_if_not_all_built: bool = "CI" in os.environ,
384386
pytest_assert_rewrites: bool = True,
385387
*,
386388
_force_assert_rewrites: bool = False,
@@ -403,6 +405,15 @@ def __init__(
403405
when an assertion fails, but requires us to load pytest.
404406
"""
405407

408+
unbuilt = sorted(pkg for pkg in packages if not package_is_built(pkg))
409+
if unbuilt:
410+
msg = "Requires unbuilt packages: " + ", ".join(unbuilt)
411+
if "PYTEST_CURRENT_TEST" not in os.environ:
412+
raise RuntimeError(msg)
413+
if skip_if_not_all_built:
414+
pytest.skip(msg)
415+
pytest.fail(msg)
416+
406417
self._pkgs = list(packages)
407418
pytest_assert_rewrites = _force_assert_rewrites or (
408419
pytest_assert_rewrites and package_is_built("pytest")

0 commit comments

Comments
 (0)