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 a test module for run_in_pyodide functions #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion pytest_pyodide/_decorator_in_pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"""

import pickle
import sys
from base64 import b64decode, b64encode
from inspect import isclass
from io import BytesIO
from types import ModuleType
from typing import Any

import pyodide_js
Expand Down Expand Up @@ -108,9 +110,15 @@ async def run_in_pyodide_main(
mod = decode(mod64)
args: tuple[Any] = decode(args64)

# Set up test module
MODULE_NAME = "test_module"
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
module = ModuleType(module_filename)
module.__file__ = module_filename
sys.modules[MODULE_NAME] = module
d = module.__dict__

# Compile and execute the ast
co = compile(mod, module_filename, "exec")
d: dict[str, Any] = {}
exec(co, d)

try:
Expand Down Expand Up @@ -142,6 +150,9 @@ def get_locals(frame):
except ImportError:
pass
return (1, encode(e))
finally:
# Remove test module
del sys.modules[MODULE_NAME]


__all__ = ["PyodideHandle", "encode"]
Loading