44# SPDX-License-Identifier: BSD-3-Clause
55
66import platform
7+ import shutil
78
89import pytest
910from 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