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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Fixed

- Clear loaded modules to remove state between runs (#1287)
- Fix intermitently failing dropdown test (#1285)

## [0.34.2] - 2025-12-09
Expand Down
43 changes: 43 additions & 0 deletions cypress/e2e/spec-wc-pyodide.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,49 @@ describe("Running the code with pyodide", () => {
});


it("reloads imported local files between code runs", () => {
cy.get("@editor")
.findByLabelText('editor text input')
.invoke("text",
`from helper import b\nb()`
);

cy.get("@editor").findByRole('button', { name: 'Add file' }).click()

cy.get("@editor")
.findByLabelText(/Name your file/)
.type("helper.py");

cy.get("@editor")
.findByRole('dialog')
.findByRole('button', { name: 'Add file' }).click()

cy.get("@editor")
.findByLabelText('editor text input')
.invoke("text", `def b():\n print('one')`);

cy.get("@editor")
.findByRole('button', { name: 'Run' }).click();

cy.get("@editor")
.find(".pyodiderunner")
.findByLabelText('Text output')
.should("contain", "one");

cy.get("@editor")
.findByLabelText('editor text input')
.invoke("text", `def b():\n print('two')`);

cy.get("@editor")
.findByRole('button', { name: 'Run' }).click();

cy.get("@editor")
.find(".pyodiderunner")
.findByLabelText('Text output')
.should("contain", "two");
});


it("runs a simple program with a built-in pyodide module", () => {
runCode(
"import simplejson as json\nprint(json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]))",
Expand Down
7 changes: 6 additions & 1 deletion src/PyodideWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@ const PyodideWorker = () => {
const clearPyodideData = async () => {
postMessage({ method: "handleLoading" });
await pyodide.runPythonAsync(`
# Clear all user-defined variables and modules
import sys
for name in list(sys.modules):
module = sys.modules[name]
if hasattr(module, '__file__') and module.__file__ and module.__file__.startswith('/home/pyodide/'):
del sys.modules[name]

for name in dir():
if not name.startswith('_') and not name=='basthon':
del globals()[name]
Expand Down
Loading