Skip to content

Commit 6044fcc

Browse files
committed
Add pytest-based tests
1 parent 92efcde commit 6044fcc

File tree

8 files changed

+74
-25
lines changed

8 files changed

+74
-25
lines changed

build/deps/python.MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ pip.parse(
2020
use_repo(pip, "py_deps", "v8_python_deps")
2121

2222
pyodide = use_extension("//build/deps:dep_pyodide.bzl", "pyodide")
23-
use_repo(pyodide, "all_pyodide_wheels_20240829.4", "all_pyodide_wheels_20250808", "beautifulsoup4_src_0.26.0a2", "beautifulsoup4_src_0.28.2", "beautifulsoup4_src_development", "fastapi_src_0.26.0a2", "fastapi_src_0.28.2", "fastapi_src_development", "pyodide-0.26.0a2", "pyodide-0.28.2", "pyodide-lock_20240829.4.json", "pyodide-lock_20250808.json", "pyodide-snapshot-baseline-4569679fb.bin", "pyodide-snapshot-baseline-61eedf943.bin", "pyodide-snapshot-ew-py-package-snapshot_fastapi-v2.bin", "pyodide-snapshot-ew-py-package-snapshot_numpy-v2.bin", "pyodide-snapshot-package_snapshot_fastapi-a6ccb56fe.bin", "pyodide-snapshot-package_snapshot_numpy-60c9cb28e.bin", "pyodide-snapshot-snapshot_a6b652a95810783f5078b9a5dbd4a07c30718acb4ff724e82c25db7353dd7f2d.bin", "pyodide_0.26.0a2_2024-03-01_75.capnp.bin", "pyodide_0.28.2_2025-01-16_6.capnp.bin", "pyodide_dev.capnp.bin", "python-workers-runtime-sdk_src_0.26.0a2", "python-workers-runtime-sdk_src_0.28.2", "python-workers-runtime-sdk_src_development", "scipy_src_0.26.0a2", "shapely_src_0.28.2", "shapely_src_development")
23+
use_repo(pyodide, "all_pyodide_wheels_20240829.4", "all_pyodide_wheels_20250808", "beautifulsoup4_src_0.26.0a2", "beautifulsoup4_src_0.28.2", "beautifulsoup4_src_development", "fastapi_src_0.26.0a2", "fastapi_src_0.28.2", "fastapi_src_development", "pyodide-0.26.0a2", "pyodide-0.28.2", "pyodide-lock_20240829.4.json", "pyodide-lock_20250808.json", "pyodide-snapshot-baseline-4569679fb.bin", "pyodide-snapshot-baseline-61eedf943.bin", "pyodide-snapshot-ew-py-package-snapshot_fastapi-v2.bin", "pyodide-snapshot-ew-py-package-snapshot_numpy-v2.bin", "pyodide-snapshot-package_snapshot_fastapi-a6ccb56fe.bin", "pyodide-snapshot-package_snapshot_numpy-60c9cb28e.bin", "pyodide-snapshot-snapshot_a6b652a95810783f5078b9a5dbd4a07c30718acb4ff724e82c25db7353dd7f2d.bin", "pyodide_0.26.0a2_2024-03-01_75.capnp.bin", "pyodide_0.28.2_2025-01-16_6.capnp.bin", "pyodide_dev.capnp.bin", "pytest-asyncio_src_0.26.0a2", "pytest-asyncio_src_0.28.2", "pytest-asyncio_src_development", "python-workers-runtime-sdk_src_0.26.0a2", "python-workers-runtime-sdk_src_0.28.2", "python-workers-runtime-sdk_src_development", "scipy_src_0.26.0a2", "shapely_src_0.28.2", "shapely_src_development")

build/python_metadata.bzl

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ def _make_bundle_version_info(versions):
104104
_check_pyodide_versions(result)
105105
return result
106106

107+
VENDORED_VERSION_INDEPENDENT = [
108+
{
109+
# Downloaded from https://pub-25a5b2f2f1b84655b185a505c7a3ad23.r2.dev/beautifulsoup4-vendored-for-ew-testing.zip
110+
"name": "beautifulsoup4",
111+
"abi": None,
112+
"sha256": "5aa09c5f549443969dda260a70e58e3ac8537bd3d29155b307a3d98b36eb70fd",
113+
},
114+
{
115+
"name": "pytest-asyncio",
116+
"abi": None,
117+
"sha256": "be25b788392d124cbdfbb9b3d13541da69a7b6b977bc9474dddaddeaab6421b4",
118+
},
119+
{
120+
"name": "python-workers-runtime-sdk",
121+
"abi": None,
122+
"sha256": "fc4fb50f73973c257277155b3cb113aa2cf68e9da8ef424ecb049b41bc463183",
123+
},
124+
]
125+
107126
BUNDLE_VERSION_INFO = _make_bundle_version_info([
108127
{
109128
"name": "0.26.0a2",
@@ -123,24 +142,13 @@ BUNDLE_VERSION_INFO = _make_bundle_version_info([
123142
"numpy_snapshot_hash": "5055deb53f404afacba73642fd10e766b123e661847e8fdf4f1ec92d8ca624dc",
124143
"fastapi_snapshot": "ew-py-package-snapshot_fastapi-v2.bin",
125144
"fastapi_snapshot_hash": "d204956a074cd74f7fe72e029e9a82686fcb8a138b509f765e664a03bfdd50fb",
126-
"vendored_packages_for_tests": [
127-
{
128-
# Downloaded from https://pub-25a5b2f2f1b84655b185a505c7a3ad23.r2.dev/beautifulsoup4-vendored-for-ew-testing.zip
129-
"name": "beautifulsoup4",
130-
"abi": None,
131-
"sha256": "5aa09c5f549443969dda260a70e58e3ac8537bd3d29155b307a3d98b36eb70fd",
132-
},
145+
"vendored_packages_for_tests": VENDORED_VERSION_INDEPENDENT + [
133146
{
134147
# Downloaded from https://pub-25a5b2f2f1b84655b185a505c7a3ad23.r2.dev/fastapi-312-vendored-for-ew-testing.zip
135148
"name": "fastapi",
136149
"abi": "3.12",
137150
"sha256": "5e6e21dbeda7c1eaadb99e6e52aa2ce45325b51e9a417198701e68e0cfd12a4c",
138151
},
139-
{
140-
"name": "python-workers-runtime-sdk",
141-
"abi": None,
142-
"sha256": "fc4fb50f73973c257277155b3cb113aa2cf68e9da8ef424ecb049b41bc463183",
143-
},
144152
{
145153
"name": "scipy",
146154
"abi": "3.12",
@@ -167,23 +175,12 @@ BUNDLE_VERSION_INFO = _make_bundle_version_info([
167175
"fastapi_snapshot_hash": "a6ccb56fe9eac265d139727d0134e8d6432c5fe25c8c0b8ec95252b13493b297",
168176
"dedicated_fastapi_snapshot": "snapshot_a6b652a95810783f5078b9a5dbd4a07c30718acb4ff724e82c25db7353dd7f2d.bin",
169177
"dedicated_fastapi_snapshot_hash": "4af6f012a5fb32f31a426e6f109e88ae85b18ee3dd131e1caaaad989cd962bbe",
170-
"vendored_packages_for_tests": [
171-
{
172-
# Downloaded from https://pub-25a5b2f2f1b84655b185a505c7a3ad23.r2.dev/beautifulsoup4-vendored-for-ew-testing.zip
173-
"name": "beautifulsoup4",
174-
"abi": None,
175-
"sha256": "5aa09c5f549443969dda260a70e58e3ac8537bd3d29155b307a3d98b36eb70fd",
176-
},
178+
"vendored_packages_for_tests": VENDORED_VERSION_INDEPENDENT + [
177179
{
178180
"name": "fastapi",
179181
"abi": "3.13",
180182
"sha256": "955091f1bd2eb33255ff2633df990bedc96e2f6294e78f2b416078777394f942",
181183
},
182-
{
183-
"name": "python-workers-runtime-sdk",
184-
"abi": None,
185-
"sha256": "fc4fb50f73973c257277155b3cb113aa2cf68e9da8ef424ecb049b41bc463183",
186-
},
187184
# {
188185
# "name": "scipy",
189186
# "abi": "3.13",

src/pyodide/internal/pool/emscriptenSetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ function getEmscriptenSettings(
161161
PYTHONHASHSEED: '111',
162162
},
163163
lockFileURL: '',
164+
enableRunUntilComplete: true,
164165
};
165166
let lockFilePromise;
166167
if (isWorkerd) {

src/pyodide/types/emscripten.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface PyodideConfig {
1010
indexURL?: string;
1111
_makeSnapshot?: boolean;
1212
lockFileURL: '';
13+
enableRunUntilComplete: boolean;
1314
}
1415

1516
type SerializedHiwireValue = { path: string[] } | { serialized: any } | null;

src/workerd/server/tests/python/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
load("//src/workerd/server/tests/python:import_tests.bzl", "gen_rust_import_tests")
22
load("//src/workerd/server/tests/python:py_wd_test.bzl", "py_wd_test", "python_test_setup")
3+
load("//src/workerd/server/tests/python/vendor_pkg_tests:vendor_test.bzl", "vendored_py_wd_test")
34

45
python_test_setup()
56

7+
vendored_py_wd_test(
8+
"pytest-asyncio",
9+
data = glob(["pytest/tests/**"]),
10+
level = 0,
11+
main_py_file = "pytest/main.py",
12+
make_snapshot = False,
13+
python_flags = ["development"],
14+
test_template = "pytest/pytest.wd-test",
15+
use_snapshot = None,
16+
)
17+
618
# Each test takes a while to start up, so if possible add additional tests to many-tests or sdk or
719
# some other existing test.
820
py_wd_test("hello")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from workers import WorkerEntrypoint
3+
4+
5+
class Default(WorkerEntrypoint):
6+
async def test(self):
7+
assert pytest.main(["/session/metadata/tests", "-vv"]) == 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Workerd = import "/workerd/workerd.capnp";
2+
3+
const unitTests :Workerd.Config = (
4+
services = [
5+
( name = "pytest-vendor-test",
6+
worker = (
7+
modules = [
8+
(name = "main.py", pythonModule = embed "pytest/main.py"),
9+
(name = "tests/test_a.py", pythonModule = embed "pytest/tests/test_a.py"),
10+
%PYTHON_VENDORED_MODULES%
11+
],
12+
compatibilityFlags = [%PYTHON_FEATURE_FLAGS, "disable_python_no_global_handlers"],
13+
)
14+
),
15+
],
16+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import asyncio
2+
3+
import pytest
4+
5+
6+
@pytest.mark.asyncio
7+
async def test_a():
8+
print("x")
9+
await asyncio.sleep(0.5)
10+
print("y")
11+
assert 1 == 2
12+
13+
14+
def test_b():
15+
assert 3 == 3

0 commit comments

Comments
 (0)