@@ -115,7 +115,7 @@ def prepare_job(job, command='hostname',
115115 pre_run = pre_run or ['echo prerun' ]
116116 post_run = post_run or ['echo postrun' ]
117117 prepare_cmds = prepare_cmds or ['echo prepare' ]
118- with rt .module_use ('unittests/modules' ):
118+ with rt .module_use (test_util . TEST_MODULES ):
119119 job .prepare (
120120 [
121121 * pre_run ,
@@ -127,6 +127,11 @@ def prepare_job(job, command='hostname',
127127 )
128128
129129
130+ def submit_job (job ):
131+ with rt .module_use (test_util .TEST_MODULES ):
132+ job .submit ()
133+
134+
130135def assert_job_script_sanity (job ):
131136 '''Assert the sanity of the produced script file.'''
132137 with open (job .script_filename ) as fp :
@@ -386,7 +391,7 @@ def test_submit(make_job, exec_ctx):
386391 minimal_job = make_job (sched_access = exec_ctx .access )
387392 prepare_job (minimal_job )
388393 assert minimal_job .nodelist is None
389- minimal_job . submit ( )
394+ submit_job ( minimal_job )
390395 assert minimal_job .jobid is not None
391396 minimal_job .wait ()
392397
@@ -403,12 +408,15 @@ def test_submit(make_job, exec_ctx):
403408 assert num_nodes == len (minimal_job .nodelist )
404409 assert 0 == minimal_job .exitcode
405410
411+ with open (minimal_job .stderr ) as stderr :
412+ assert not stderr .read ().strip ()
413+
406414
407415def test_submit_timelimit (minimal_job , local_only ):
408416 minimal_job .time_limit = '2s'
409417 prepare_job (minimal_job , 'sleep 10' )
410418 t_job = time .time ()
411- minimal_job . submit ( )
419+ submit_job ( minimal_job )
412420 assert minimal_job .jobid is not None
413421 minimal_job .wait ()
414422 t_job = time .time () - t_job
@@ -430,7 +438,7 @@ def test_submit_job_array(make_job, slurm_only, exec_ctx):
430438 job = make_job (sched_access = exec_ctx .access )
431439 job .options = ['--array=0-1' ]
432440 prepare_job (job , command = 'echo "Task id: ${SLURM_ARRAY_TASK_ID}"' )
433- job . submit ( )
441+ submit_job ( job )
434442 job .wait ()
435443 if job .scheduler .registered_name == 'slurm' :
436444 assert job .exitcode == 0
@@ -445,7 +453,7 @@ def test_cancel(make_job, exec_ctx):
445453 prepare_job (minimal_job , 'sleep 30' )
446454 t_job = time .time ()
447455
448- minimal_job . submit ( )
456+ submit_job ( job )
449457 minimal_job .cancel ()
450458
451459 # We give some time to the local scheduler for the TERM signal to be
@@ -484,7 +492,7 @@ def test_wait_before_submit(minimal_job):
484492def test_finished (make_job , exec_ctx ):
485493 minimal_job = make_job (sched_access = exec_ctx .access )
486494 prepare_job (minimal_job , 'sleep 2' )
487- minimal_job . submit ( )
495+ submit_job ( minimal_job )
488496 assert not minimal_job .finished ()
489497 minimal_job .wait ()
490498
@@ -498,7 +506,7 @@ def test_finished_before_submit(minimal_job):
498506def test_finished_raises_error (make_job , exec_ctx ):
499507 minimal_job = make_job (sched_access = exec_ctx .access )
500508 prepare_job (minimal_job , 'echo hello' )
501- minimal_job . submit ( )
509+ submit_job ( minimal_job )
502510 minimal_job .wait ()
503511
504512 # Emulate an error during polling and verify that it is raised correctly
@@ -555,7 +563,7 @@ def test_guess_num_tasks(minimal_job, scheduler):
555563 minimal_job .num_tasks = 0
556564 minimal_job ._sched_flex_alloc_nodes = 'idle'
557565 prepare_job (minimal_job )
558- minimal_job . submit ( )
566+ submit_job ( minimal_job )
559567 minimal_job .wait ()
560568 assert minimal_job .num_tasks == 1
561569 elif scheduler .registered_name in ('slurm' , 'squeue' ):
@@ -596,7 +604,7 @@ def state(self):
596604
597605 type(minimal_job ).state = property (state )
598606 prepare_job (minimal_job , 'sleep 30' )
599- minimal_job . submit ( )
607+ submit_job ( minimal_job )
600608 with pytest .raises (JobError ,
601609 match = 'maximum pending time exceeded' ):
602610 minimal_job .wait ()
@@ -649,7 +657,7 @@ def test_cancel_with_grace(minimal_job, scheduler, local_only):
649657 pre_run = ['trap -- "" TERM' ],
650658 post_run = ['echo $!' , 'wait' ],
651659 prepare_cmds = ['' ])
652- minimal_job . submit ( )
660+ submit_job ( minimal_job )
653661
654662 # Stall a bit here to let the the spawned process start and install its
655663 # signal handler for SIGTERM
@@ -696,7 +704,7 @@ def test_cancel_term_ignore(minimal_job, scheduler, local_only):
696704 pre_run = ['' ],
697705 post_run = ['' ],
698706 prepare_cmds = ['' ])
699- minimal_job . submit ( )
707+ submit_job ( minimal_job )
700708
701709 # Stall a bit here to let the the spawned process start and install its
702710 # signal handler for SIGTERM
0 commit comments