Skip to content
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"
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"]