Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions pytest_pyodide/decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
import functools
import os
import pickle
import sys
from base64 import b64decode, b64encode
Expand Down Expand Up @@ -383,6 +384,7 @@
packages: Collection[str] = (),
pytest_assert_rewrites: bool = True,
*,
skip_if_not_all_built: bool = "CI" in os.environ,
Copy link
Member

Choose a reason for hiding this comment

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

I think setting the default to "CI" in os.environ might be confusing to users, as they will silently get different behavior in local and in CI. How about 1) setting the default to False, and make it configurable in the CLI option

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. Also, it seems that what we really want is to skip if it's in one of the earlier test jobs (e.g., test_packages_no_numpy_dependents) but fail if it's in the final job.

Copy link
Member

Choose a reason for hiding this comment

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

if it's in one of the earlier test jobs (e.g., test_packages_no_numpy_dependents) but fail if it's in the final job.

Yeah, makes sense.

_force_assert_rewrites: bool = False,
):
"""
Expand All @@ -402,8 +404,8 @@
If True, use pytest assertion rewrites. This gives better error messages
when an assertion fails, but requires us to load pytest.
"""

self._pkgs = list(packages)
self._skip_if_not_all_built = skip_if_not_all_built
pytest_assert_rewrites = _force_assert_rewrites or (
pytest_assert_rewrites and package_is_built("pytest")
)
Expand Down Expand Up @@ -447,10 +449,18 @@
def _run(self, selenium: SeleniumType, args: tuple):
"""The main runner, called from the AST generated in _create_outer_func."""
__tracebackhide__ = True
code = self._code_template(args)
if self._pkgs:
selenium.load_package(self._pkgs)

unbuilt = sorted(pkg for pkg in self._pkgs if not package_is_built(pkg))
if unbuilt:
msg = "Requires unbuilt packages: " + ", ".join(unbuilt)
if "PYTEST_CURRENT_TEST" not in os.environ:
raise RuntimeError(msg)
if self._skip_if_not_all_built:
pytest.skip(msg)
pytest.fail(msg)

Check warning on line 460 in pytest_pyodide/decorator.py

View check run for this annotation

Codecov / codecov/patch

pytest_pyodide/decorator.py#L455-L460

Added lines #L455 - L460 were not covered by tests
selenium.load_package(self._pkgs)

code = self._code_template(args)
r = selenium.run_async(code)
[status, result] = r

Expand Down
2 changes: 2 additions & 0 deletions pytest_pyodide/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def run_webworker(self, code):
)

def load_package(self, packages):
if not packages:
return
self.run_js(f"await pyodide.loadPackage({packages!r})")


Expand Down