diff --git a/ci/run_cuopt_pytests.sh b/ci/run_cuopt_pytests.sh index 9ee7780dc0..c9b7a0acad 100755 --- a/ci/run_cuopt_pytests.sh +++ b/ci/run_cuopt_pytests.sh @@ -36,7 +36,7 @@ rc=0 if [ "${IS_NIGHTLY}" = "nightly" ]; then pytest -s --cache-clear --reruns 2 --reruns-delay 5 -p cuopt_rerun_xml "$@" tests || rc=$? else - pytest -s --cache-clear "$@" tests || rc=$? + pytest -s --cache-clear -n 8 "$@" tests || rc=$? fi # If not a crash, exit normally diff --git a/ci/run_cuopt_server_pytests.sh b/ci/run_cuopt_server_pytests.sh index 1580c038f0..ceb00a3800 100755 --- a/ci/run_cuopt_server_pytests.sh +++ b/ci/run_cuopt_server_pytests.sh @@ -35,7 +35,7 @@ rc=0 if [ "${IS_NIGHTLY}" = "nightly" ]; then pytest -s --cache-clear --reruns 2 --reruns-delay 5 -p cuopt_rerun_xml "$@" tests || rc=$? else - pytest -s --cache-clear "$@" tests || rc=$? + pytest -s --cache-clear -n 8 "$@" tests || rc=$? fi if [ "${rc}" -le 128 ]; then diff --git a/conda/environments/all_cuda-129_arch-aarch64.yaml b/conda/environments/all_cuda-129_arch-aarch64.yaml index a084f1931c..ac52f72af1 100644 --- a/conda/environments/all_cuda-129_arch-aarch64.yaml +++ b/conda/environments/all_cuda-129_arch-aarch64.yaml @@ -59,6 +59,7 @@ dependencies: - pyrsistent - pytest-cov - pytest-rerunfailures +- pytest-xdist - pytest<9.0 - python>=3.11,<3.15 - pyyaml>=6.0.0 diff --git a/conda/environments/all_cuda-129_arch-x86_64.yaml b/conda/environments/all_cuda-129_arch-x86_64.yaml index 8f607577d2..40758e9d6d 100644 --- a/conda/environments/all_cuda-129_arch-x86_64.yaml +++ b/conda/environments/all_cuda-129_arch-x86_64.yaml @@ -59,6 +59,7 @@ dependencies: - pyrsistent - pytest-cov - pytest-rerunfailures +- pytest-xdist - pytest<9.0 - python>=3.11,<3.15 - pyyaml>=6.0.0 diff --git a/conda/environments/all_cuda-133_arch-aarch64.yaml b/conda/environments/all_cuda-133_arch-aarch64.yaml index db32073fc6..2bd3831315 100644 --- a/conda/environments/all_cuda-133_arch-aarch64.yaml +++ b/conda/environments/all_cuda-133_arch-aarch64.yaml @@ -59,6 +59,7 @@ dependencies: - pyrsistent - pytest-cov - pytest-rerunfailures +- pytest-xdist - pytest<9.0 - python>=3.11,<3.15 - pyyaml>=6.0.0 diff --git a/conda/environments/all_cuda-133_arch-x86_64.yaml b/conda/environments/all_cuda-133_arch-x86_64.yaml index 51885b14f5..d3e3ec88ed 100644 --- a/conda/environments/all_cuda-133_arch-x86_64.yaml +++ b/conda/environments/all_cuda-133_arch-x86_64.yaml @@ -59,6 +59,7 @@ dependencies: - pyrsistent - pytest-cov - pytest-rerunfailures +- pytest-xdist - pytest<9.0 - python>=3.11,<3.15 - pyyaml>=6.0.0 diff --git a/dependencies.yaml b/dependencies.yaml index 42259096ed..f5ccef91bc 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -309,6 +309,7 @@ dependencies: - pytest<9.0 - pytest-cov - pytest-rerunfailures + - pytest-xdist test_python_cuopt: common: - output_types: [conda] diff --git a/python/cuopt/cuopt/tests/linear_programming/test_cpu_only_execution.py b/python/cuopt/cuopt/tests/linear_programming/test_cpu_only_execution.py index 07ae224ef9..09dd6c395b 100644 --- a/python/cuopt/cuopt/tests/linear_programming/test_cpu_only_execution.py +++ b/python/cuopt/cuopt/tests/linear_programming/test_cpu_only_execution.py @@ -428,7 +428,13 @@ def _start_grpc_server_fixture(port_offset): if server_bin is None: pytest.skip("cuopt_grpc_server not found") - port = int(os.environ.get("CUOPT_TEST_PORT_BASE", "18000")) + port_offset + _worker = os.environ.get("PYTEST_XDIST_WORKER", "gw0") + worker_id = int(_worker[2:]) if _worker.startswith("gw") else 0 + port = ( + int(os.environ.get("CUOPT_TEST_PORT_BASE", "18000")) + + port_offset + + worker_id + ) proc = subprocess.Popen( [server_bin, "--port", str(port), "--workers", "1"], stdout=subprocess.DEVNULL, diff --git a/python/cuopt/pyproject.toml b/python/cuopt/pyproject.toml index c2d8ed29cb..0353224663 100644 --- a/python/cuopt/pyproject.toml +++ b/python/cuopt/pyproject.toml @@ -47,6 +47,7 @@ test = [ "numpy>=2.0,<3.0", "pytest-cov", "pytest-rerunfailures", + "pytest-xdist", "pytest<9.0", "rapids-logger==0.2.*,>=0.0.0a0", ] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`. diff --git a/python/cuopt_self_hosted/pyproject.toml b/python/cuopt_self_hosted/pyproject.toml index fdb3d2a377..8210c67cc4 100644 --- a/python/cuopt_self_hosted/pyproject.toml +++ b/python/cuopt_self_hosted/pyproject.toml @@ -37,6 +37,7 @@ classifiers = [ test = [ "pytest-cov", "pytest-rerunfailures", + "pytest-xdist", "pytest<9.0", ] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`. mps = [ diff --git a/python/cuopt_server/cuopt_server/tests/utils/utils.py b/python/cuopt_server/cuopt_server/tests/utils/utils.py index eaefdb2a25..496794b5a4 100644 --- a/python/cuopt_server/cuopt_server/tests/utils/utils.py +++ b/python/cuopt_server/cuopt_server/tests/utils/utils.py @@ -17,6 +17,12 @@ RAPIDS_DATASET_ROOT_DIR = os.path.join(RAPIDS_DATASET_ROOT_DIR, "datasets") +def _worker_port(base=5555): + _worker = os.environ.get("PYTEST_XDIST_WORKER", "gw0") + worker_id = int(_worker[2:]) if _worker.startswith("gw") else 0 + return base + worker_id + + def generate_json_data(**args): return {arg[0]: arg[1] for arg in args.items() if arg[1] is not None} @@ -345,7 +351,7 @@ def cuoptproc(request): "-i", "0.0.0.0", "-p", - "5555", + str(_worker_port()), "-l", "debug", ] @@ -359,7 +365,7 @@ def shutdown(): class RequestClient: - def __init__(self, port=5555): + def __init__(self, port=_worker_port()): self.ip = "127.0.0.1" self.port = port self.url = f"http://{self.ip}:{self.port}" diff --git a/python/cuopt_server/pyproject.toml b/python/cuopt_server/pyproject.toml index 363b230f4d..20499da847 100644 --- a/python/cuopt_server/pyproject.toml +++ b/python/cuopt_server/pyproject.toml @@ -49,6 +49,7 @@ test = [ "pexpect", "pytest-cov", "pytest-rerunfailures", + "pytest-xdist", "pytest<9.0", "requests", ] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.