-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
/
pytest-pyodide.js
53 lines (44 loc) · 1.62 KB
/
pytest-pyodide.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { opendir } = require('node:fs/promises');
const { loadPyodide } = require("pyodide");
async function main() {
let exit_code = 0;
try {
global.pyodide = await loadPyodide();
let pyodide = global.pyodide;
const FS = pyodide.FS;
const NODEFS = FS.filesystems.NODEFS;
let mountDir = "/mnt";
pyodide.FS.mkdir(mountDir);
pyodide.FS.mount(pyodide.FS.filesystems.NODEFS, { root: "." }, mountDir);
await pyodide.loadPackage(["micropip"]);
await pyodide.runPythonAsync(`
import glob
import micropip
wheels = glob.glob('/mnt/dist/*.whl')
wheels = [f'emfs://{wheel}' for wheel in wheels]
print(f'installing wheels: {wheels}')
await micropip.install(wheels);
pkg_list = micropip.list()
print(pkg_list)
`);
// Pyodide is built without OpenMP, need to set environment variable to
// skip related test
await pyodide.runPythonAsync(`
import os
os.environ['SKLEARN_SKIP_OPENMP_TEST'] = 'true'
`);
await pyodide.runPythonAsync("import micropip; micropip.install('pytest')");
let pytest = pyodide.pyimport("pytest");
let args = process.argv.slice(2);
console.log('pytest args:', args);
exit_code = pytest.main(pyodide.toPy(args));
} catch (e) {
console.error(e);
// Arbitrary exit code here. I have seen this code reached instead of a
// Pyodide fatal error sometimes
exit_code = 66;
} finally {
process.exit(exit_code);
}
}
main();