Skip to content
Draft
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
14 changes: 9 additions & 5 deletions pytest_pyodide/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
def run_js(self, code: str):
...

def is_closed(self):
...

Check warning on line 39 in pytest_pyodide/decorator.py

View check run for this annotation

Codecov / codecov/patch

pytest_pyodide/decorator.py#L39

Added line #L39 was not covered by tests


class _ReadableFileobj(Protocol):
def read(self, __n: int) -> bytes:
Expand Down Expand Up @@ -85,11 +88,12 @@
return
ptr = self.ptr
self.ptr = None
self.selenium.run_js(
f"""
pyodide._module._Py_DecRef({ptr});
"""
)
if not self.selenium.is_closed():
self.selenium.run_js(
f"""
pyodide._module._Py_DecRef({ptr});
"""
)


def _encode(obj: Any) -> str:
Expand Down
12 changes: 12 additions & 0 deletions pytest_pyodide/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
def quit(self):
raise NotImplementedError()

def is_closed(self):
raise NotImplementedError()

Check warning on line 158 in pytest_pyodide/runner.py

View check run for this annotation

Codecov / codecov/patch

pytest_pyodide/runner.py#L158

Added line #L158 was not covered by tests

def refresh(self):
raise NotImplementedError()

Expand Down Expand Up @@ -331,6 +334,8 @@


class _SeleniumBaseRunner(_BrowserBaseRunner):
_is_closed = False

def goto(self, page):
self.driver.get(page)

Expand All @@ -340,11 +345,15 @@

def quit(self):
self.driver.quit()
self._is_closed = True

def refresh(self):
self.driver.refresh()
self.javascript_setup()

def is_closed(self):
return self._is_closed

def run_js_inner(self, code, check_code):
wrapper = """
let cb = arguments[arguments.length - 1];
Expand Down Expand Up @@ -393,6 +402,9 @@
def quit(self):
self.driver.close()

def is_closed(self):
return self.driver.is_closed()

Check warning on line 406 in pytest_pyodide/runner.py

View check run for this annotation

Codecov / codecov/patch

pytest_pyodide/runner.py#L406

Added line #L406 was not covered by tests

def refresh(self):
self.driver.reload()
self.javascript_setup()
Expand Down
14 changes: 14 additions & 0 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,17 @@ def fn_with_complex_args2(selenium, a, /, b, *args, c, d=Callable, **kwargs):
fn_with_complex_args2(selenium, 5, 6, 7, 8, 9, a=8, c=7, q=11)
with pytest.raises(TypeError, match="multiple values"):
fn_with_complex_args2(selenium, 5, 6, 7, 8, 9, b=8, c=7, q=11)


def test_handle_finalizer(selenium):
"""test that the finalizer does not call run_js on a closed runner"""
from unittest.mock import create_autospec

from pytest_pyodide.decorator import PyodideHandle

selenium = create_autospec(spec=selenium)
selenium.is_closed.return_value = True
handle = PyodideHandle(selenium, 0xC0FFEE)
del handle
selenium.is_closed.assert_called()
selenium.run_js.assert_not_called()
Empty file added tomtests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions tomtests/test_handle_bug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from pytest_pyodide import run_in_pyodide


@pytest.fixture
@run_in_pyodide
def macguffin(selenium):
from pytest_pyodide.decorator import PyodideHandle

s = {"a": 1}
return PyodideHandle(s)


@run_in_pyodide
def test_macguffin(selenium, macguffin):
assert macguffin["a"] == 1
Loading