diff --git a/noxfile.py b/noxfile.py index 4a3cca99f..957467855 100644 --- a/noxfile.py +++ b/noxfile.py @@ -173,8 +173,9 @@ def unit_tests(session: nox.Session): behave_cmd = session.bin + "/behave-parallel" parallel_args = _behave_parallel_args(session.posargs) - # If a specific feature file is passed, run only that file - if session.posargs and session.posargs[0].endswith(".feature"): + # If specific feature files are passed, run only those files + has_feature_files = any(arg.endswith(".feature") for arg in session.posargs) + if has_feature_files: args = [ behave_cmd, "-q", @@ -562,7 +563,8 @@ def coverage_report(session: nox.Session): # Build behave-parallel args (sequential for coverage). behave_cmd = session.bin + "/behave-parallel" - if session.posargs and session.posargs[0].endswith(".feature"): + has_feature_files = any(arg.endswith(".feature") for arg in session.posargs) + if has_feature_files: behave_args = [ behave_cmd, "-q", diff --git a/scripts/run_behave_parallel.py b/scripts/run_behave_parallel.py index 14721d779..b3d6e4d80 100644 --- a/scripts/run_behave_parallel.py +++ b/scripts/run_behave_parallel.py @@ -337,7 +337,18 @@ def main(argv: list[str] | None = None) -> None: start = time.monotonic() - if processes <= 1 or coverage_mode or len(feature_paths) == 1: + # Run sequentially if: + # - processes <= 1 (explicitly requested) + # - coverage_mode (slipcover requires single process) + # - only 1 feature file (no parallelism benefit) + # - very few feature files relative to processes (fork overhead > benefit) + # When feature_paths <= 2, sequential is faster and avoids fork deadlocks + if ( + processes <= 1 + or coverage_mode + or len(feature_paths) == 1 + or len(feature_paths) <= 2 + ): # ---- sequential in-process mode ---- _, total = _run_features_inprocess(feature_paths, other_args) else: