Skip to content

Commit a2b3117

Browse files
committed
Gracefully handle absence of bids-validator, and allow running it through npx
1 parent 4f12d19 commit a2b3117

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

mne_bids/tests/conftest.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55

66
import platform
7+
import shutil
78

89
import pytest
910
from mne.utils import run_subprocess
@@ -19,9 +20,28 @@ def _bids_validate():
1920
else:
2021
shell = False
2122

22-
def _validate(bids_root):
23-
cmd = ["bids-validator", bids_root]
24-
run_subprocess(cmd, shell=shell)
23+
# If neither bids-validator nor npx are available, we cannot validate BIDS
24+
# datasets, so we skip the tests that require validation.
25+
# If both are available, we prefer bids-validator, but we can use npx as a fallback.
26+
27+
has_validator = shutil.which("bids-validator") is not None
28+
has_npx = shutil.which("npx") is not None
29+
30+
if not has_validator and not has_npx:
31+
pytest.skip(
32+
"bids-validator or npx is required to run BIDS validation tests. "
33+
"Please install the BIDS validator or ensure npx is available."
34+
)
35+
elif not has_validator:
36+
37+
def _validate(bids_root):
38+
cmd = ["npx", "bids-validator@latest", bids_root]
39+
run_subprocess(cmd, shell=shell)
40+
else:
41+
42+
def _validate(bids_root):
43+
cmd = ["bids-validator", bids_root]
44+
run_subprocess(cmd, shell=shell)
2545

2646
return _validate
2747

0 commit comments

Comments
 (0)