@@ -311,21 +311,57 @@ def check_test(ctest, expected_lines):
311
311
312
312
@unittest .skipIf (not has_module_cmd () and find_module_init () is None ,
313
313
"Could not find a module system." )
314
- def test_module_purge (self ):
315
- """Test that a module purge is performed when building and running tests."""
314
+ def test_run_module_purge (self ):
315
+ """Test that a module purge is performed when running tests."""
316
316
317
+ # Test that a module purge is performed by default
317
318
test_cfg = self ._quick_test_cfg ()
318
319
test_cfg ['run' ]['cmds' ] = [
319
320
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1' ,
320
321
]
321
322
test_cfg ['run' ]['preamble' ].append ('module load test_mod1 || exit 2' )
322
323
323
- test = self ._quick_test (test_cfg , purge = False )
324
+ test = self ._quick_test (test_cfg )
324
325
run_result = test .run ()
325
326
326
- self .assertEqual (run_result , 1 )
327
+ self .assertEqual (run_result , 0 )
327
328
329
+ # Check that we can disable purging
330
+ test_cfg = self ._quick_test_cfg ()
331
+ test_cfg ['run' ]['cmds' ] = [
332
+ '[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1' ,
333
+ ]
334
+ test_cfg ['run' ]['preamble' ].append ('module load test_mod1 || exit 2' )
335
+ test_config ["run" ]["purge_modules" ] = False
328
336
test = self ._quick_test (test_cfg )
329
337
run_result = test .run ()
330
338
331
- self .assertEqual (run_result , 0 )
339
+ self .assertEqual (run_result , 1 )
340
+
341
+ def test_build_module_purge (self ):
342
+ """Test that a module purge is performed when building tests."""
343
+
344
+ # Test that a module purge is performed by default
345
+ test_cfg = self ._quick_test_cfg ()
346
+ test_cfg ['build' ]['cmds' ] = [
347
+ "# This comment exists so the test hashes to a distinct value"
348
+ '[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1' ,
349
+ ]
350
+ test_cfg ['run' ]['preamble' ].append ('module load test_mod1 || exit 2' )
351
+
352
+ test = self ._quick_test (test_cfg )
353
+ build_result = test .build ()
354
+
355
+ self .assertEqual (build_result , 0 )
356
+
357
+ # Check that we can disable purging
358
+ test_cfg = self ._quick_test_cfg ()
359
+ test_cfg ['build' ]['cmds' ] = [
360
+ '[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1' ,
361
+ ]
362
+ test_cfg ['build' ]['preamble' ].append ('module load test_mod1 || exit 2' )
363
+ test_cfg ["build" ]["purge_modules" ] = False
364
+ test = self ._quick_test (test_cfg )
365
+ build_result = test .build ()
366
+
367
+ self .assertEqual (build_result , 1 )
0 commit comments