|
11 | 11 | import pytest
|
12 | 12 | from _pytest.terminal import TerminalReporter
|
13 | 13 |
|
14 |
| -class PytestParallelError(ValueError): |
15 |
| - pass |
| 14 | +from .exception import PytestParallelUsageError, PytestParallelInternalError |
16 | 15 |
|
17 | 16 | # --------------------------------------------------------------------------
|
18 | 17 | def pytest_addoption(parser):
|
@@ -58,13 +57,13 @@ def pytest_addoption(parser):
|
58 | 57 | ' (because importing mpi4py.MPI makes the current process look like and MPI process,' \
|
59 | 58 | ' and SLURM does not like that)'
|
60 | 59 | if os.getenv('I_MPI_MPIRUN') is not None:
|
61 |
| - err_msg = 'Internal pytest_parallel error: the environment variable I_MPI_MPIRUN is set' \ |
| 60 | + err_msg = 'The environment variable I_MPI_MPIRUN is set' \ |
62 | 61 | f' (it has value "{os.getenv("I_MPI_MPIRUN")}"),\n' \
|
63 | 62 | ' while pytest was invoked with "--scheduler=slurm".\n' \
|
64 | 63 | ' This indicates that pytest was run through MPI, and SLURM generally does not like that.\n' \
|
65 | 64 | ' With "--scheduler=slurm", just run `pytest` directly, not through `mpirun/mpiexec/srun`,\n' \
|
66 | 65 | ' because it will launch MPI itself (you may want to use --n-workers=<number of processes>).'
|
67 |
| - raise PytestParallelError(err_msg) |
| 66 | + raise PytestParallelInternalError(err_msg) |
68 | 67 |
|
69 | 68 | r = subprocess.run(['env','--null'], stdout=subprocess.PIPE) # `--null`: end each output line with NUL, required by `sbatch --export-file`
|
70 | 69 |
|
@@ -109,41 +108,41 @@ def pytest_configure(config):
|
109 | 108 | assert not is_worker, f'Internal pytest_parallel error `--_worker` not available with`--scheduler={scheduler}`'
|
110 | 109 | if scheduler in ['slurm', 'shell'] and not is_worker:
|
111 | 110 | if n_workers is None:
|
112 |
| - raise PytestParallelError(f'You need to specify `--n-workers` when `--scheduler={scheduler}`') |
| 111 | + raise PytestParallelUsageError(f'You need to specify `--n-workers` when `--scheduler={scheduler}`') |
113 | 112 | if scheduler != 'slurm':
|
114 | 113 | if slurm_options is not None:
|
115 |
| - raise PytestParallelError('Option `--slurm-options` only available when `--scheduler=slurm`') |
| 114 | + raise PytestParallelUsageError('Option `--slurm-options` only available when `--scheduler=slurm`') |
116 | 115 | if slurm_srun_options is not None:
|
117 |
| - raise PytestParallelError('Option `--slurms-run-options` only available when `--scheduler=slurm`') |
| 116 | + raise PytestParallelUsageError('Option `--slurms-run-options` only available when `--scheduler=slurm`') |
118 | 117 | if slurm_init_cmds is not None:
|
119 |
| - raise PytestParallelError('Option `--slurm-init-cmds` only available when `--scheduler=slurm`') |
| 118 | + raise PytestParallelUsageError('Option `--slurm-init-cmds` only available when `--scheduler=slurm`') |
120 | 119 | if slurm_file is not None:
|
121 |
| - raise PytestParallelError('Option `--slurm-file` only available when `--scheduler=slurm`') |
| 120 | + raise PytestParallelUsageError('Option `--slurm-file` only available when `--scheduler=slurm`') |
122 | 121 |
|
123 | 122 | if scheduler in ['shell', 'slurm'] and not is_worker:
|
124 | 123 | from mpi4py import MPI
|
125 | 124 | if MPI.COMM_WORLD.size != 1:
|
126 | 125 | err_msg = 'Do not launch `pytest_parallel` on more that one process when `--scheduler=shell` or `--scheduler=slurm`.\n' \
|
127 | 126 | '`pytest_parallel` will spawn MPI processes itself.\n' \
|
128 | 127 | f'You may want to use --n-workers={MPI.COMM_WORLD.size}.'
|
129 |
| - raise PytestParallelError(err_msg) |
| 128 | + raise PytestParallelUsageError(err_msg) |
130 | 129 |
|
131 | 130 |
|
132 | 131 |
|
133 | 132 | if scheduler == 'slurm' and not is_worker:
|
134 | 133 | if slurm_options is None and slurm_file is None:
|
135 |
| - raise PytestParallelError('You need to specify either `--slurm-options` or `--slurm-file` when `--scheduler=slurm`') |
| 134 | + raise PytestParallelUsageError('You need to specify either `--slurm-options` or `--slurm-file` when `--scheduler=slurm`') |
136 | 135 | if slurm_options:
|
137 | 136 | if slurm_file:
|
138 |
| - raise PytestParallelError('You need to specify either `--slurm-options` or `--slurm-file`, but not both') |
| 137 | + raise PytestParallelUsageError('You need to specify either `--slurm-options` or `--slurm-file`, but not both') |
139 | 138 | if slurm_file:
|
140 | 139 | if slurm_options:
|
141 |
| - raise PytestParallelError('You need to specify either `--slurm-options` or `--slurm-file`, but not both') |
| 140 | + raise PytestParallelUsageError('You need to specify either `--slurm-options` or `--slurm-file`, but not both') |
142 | 141 | if slurm_init_cmds:
|
143 |
| - raise PytestParallelError('You cannot specify `--slurm-init-cmds` together with `--slurm-file`') |
| 142 | + raise PytestParallelUsageError('You cannot specify `--slurm-init-cmds` together with `--slurm-file`') |
144 | 143 |
|
145 | 144 | if '-n=' in slurm_options or '--ntasks=' in slurm_options:
|
146 |
| - raise PytestParallelError('Do not specify `-n/--ntasks` in `--slurm-options` (it is deduced from the `--n-worker` value).') |
| 145 | + raise PytestParallelUsageError('Do not specify `-n/--ntasks` in `--slurm-options` (it is deduced from the `--n-worker` value).') |
147 | 146 |
|
148 | 147 | from .slurm_scheduler import SlurmScheduler
|
149 | 148 |
|
|
0 commit comments