Skip to content

Commit 0e5e4cb

Browse files
committed
Add argument to disable module purging
1 parent caf8fc1 commit 0e5e4cb

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

lib/pavilion/commands/run.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def _generic_arguments(parser):
107107
"should be necessary only if the system or user environment "
108108
"under which Pavilion runs has changed."
109109
)
110+
parser.add_argument(
111+
'--no-purge', action='store_false', default=True, dest='purge',
112+
help="Do not perform a module purge before running tests. Modules "
113+
"are purged by default."
114+
)
110115
parser.add_argument(
111116
'tests', nargs='*', action='store', metavar='TEST_NAME',
112117
help='The name of the tests to run. These may be suite names (in '
@@ -193,7 +198,8 @@ def run(self, pav_cfg, args):
193198
series_obj.run(
194199
build_only=self.BUILD_ONLY,
195200
rebuild=args.rebuild,
196-
local_builds_only=local_builds_only)
201+
local_builds_only=local_builds_only,
202+
purge=args.purge)
197203
self.last_tests = list(series_obj.tests.values())
198204
except TestSeriesError as err:
199205
self.last_tests = list(series_obj.tests.values())

lib/pavilion/series/series.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def check_cancelled(self) -> bool:
418418
return False
419419

420420
def run(self, build_only: bool = False, rebuild: bool = False,
421-
local_builds_only: bool = False):
421+
local_builds_only: bool = False, purge: bool = True):
422422
"""Build and kickoff all of the test sets in the series.
423423
424424
:param build_only: Only build the tests, do not run them.
@@ -471,7 +471,7 @@ def run(self, build_only: bool = False, rebuild: bool = False,
471471

472472
try:
473473
self._run_set(test_set, build_only=build_only,
474-
rebuild=rebuild, local_builds_only=local_builds_only)
474+
rebuild=rebuild, local_builds_only=local_builds_only, purge=purge)
475475
except TestSetError as err:
476476
self.status.set(SERIES_STATES.ERROR,
477477
"Error running test set {}. See the series log "
@@ -506,15 +506,16 @@ def run(self, build_only: bool = False, rebuild: bool = False,
506506
# Completion will be set when looked for.
507507

508508

509-
def _run_set(self, test_set: TestSet, build_only: bool, rebuild: bool, local_builds_only: bool):
509+
def _run_set(self, test_set: TestSet, build_only: bool, rebuild: bool, local_builds_only: bool,
510+
purge: bool):
510511
"""Run all requested tests in the given test set."""
511512

512513
# Track which builds we've already marked as deprecated, when doing rebuilds.
513514
deprecated_builds = set()
514515
failed_builds = dict()
515516
tests_running = 0
516517

517-
for test_batch in test_set.make_iter(build_only, rebuild, local_builds_only):
518+
for test_batch in test_set.make_iter(build_only, rebuild, local_builds_only, purge):
518519

519520
# Add all the tests we created to this test set.
520521
self._add_tests(test_batch, test_set.iter_name)

lib/pavilion/series/test_set.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __ordered_split(self) -> List['TestSet']:
189189

190190
return test_sets
191191

192-
def make_iter(self, build_only=False, rebuild=False, local_builds_only=False) \
192+
def make_iter(self, build_only=False, rebuild=False, local_builds_only=False, purge=True) \
193193
-> Iterator[List[TestRun]]:
194194
"""Resolve the given tests names and options into actual test run objects, and print
195195
the test creation status. This returns an iterator over batches tests, respecting the
@@ -277,7 +277,7 @@ def make_iter(self, build_only=False, rebuild=False, local_builds_only=False) \
277277
try:
278278
test_run = TestRun(pav_cfg=self.pav_cfg, config=ptest.config,
279279
var_man=ptest.var_man, rebuild=rebuild,
280-
build_only=build_only)
280+
build_only=build_only, purge=purge)
281281
if not test_run.skipped:
282282
test_run.save()
283283
self.tests.append(test_run)
@@ -339,12 +339,12 @@ def make_iter(self, build_only=False, rebuild=False, local_builds_only=False) \
339339
self.all_tests_made = True
340340

341341

342-
def make(self, build_only=False, rebuild=False, local_builds_only=False):
342+
def make(self, build_only=False, rebuild=False, local_builds_only=False, purge=True):
343343
"""As per make_iter(), but create all of the tests. This doesn't
344344
respect batch sizes, etc, and is entirely for simplifying unit testing."""
345345

346346
all_tests = []
347-
for test_batch in self.make_iter(build_only, rebuild, local_builds_only):
347+
for test_batch in self.make_iter(build_only, rebuild, local_builds_only, purge):
348348
all_tests.extend(test_batch)
349349

350350
return all_tests

lib/pavilion/test_run/test_attrs.py

+3
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ def _get_status_file(self) -> Optional[TestStatusFile]:
374374
name = basic_attr(
375375
name='name',
376376
doc="The full name of the test.")
377+
purge = basic_attr(
378+
name='purge',
379+
doc="Whether or not the test will perform a module purge before building/running.")
377380
rebuild = basic_attr(
378381
name='rebuild',
379382
doc="Whether or not this test will rebuild it's build.")

lib/pavilion/test_run/test_run.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class TestRun(TestAttributes):
101101
"""Directory that holds build templates."""
102102

103103
def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager = None,
104-
_id: int = None, rebuild: bool = False, build_only: bool = False):
104+
_id: int = None, rebuild: bool = False, build_only: bool = False,
105+
purge: bool = True):
105106
"""Create an new TestRun object. If loading an existing test
106107
instance, use the ``TestRun.from_id()`` method.
107108
@@ -110,6 +111,7 @@ def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager
110111
:param bool build_only: Only build this test run, do not run it.
111112
:param bool rebuild: After determining the build name, deprecate it and
112113
select a new, non-deprecated build.
114+
:param bool purge: Whether or not to perform a module purge before running/building
113115
:param int _id: The test id of an existing test. (You should be using
114116
TestRun.load)."""
115117

@@ -150,6 +152,7 @@ def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager
150152
# Set basic attributes
151153
self.id = id_tmp # pylint: disable=invalid-name
152154
self.build_only = build_only
155+
self.purge = purge
153156
self._complete = False
154157
self.created = time.time()
155158
self.name = self.make_name(config)
@@ -1148,13 +1151,14 @@ def _write_script(self, stype: str, path: Path, config: dict, module_wrappers: d
11481151

11491152
script.command(f'echo "(pav) Setting up {stype} environment."')
11501153

1151-
1152-
modules = config.get('modules', [])
1153-
if modules:
1154+
if self.purge:
11541155
script.newline()
11551156
script.comment("Start with a fresh environment")
11561157
script.module_purge()
11571158

1159+
modules = config.get('modules', [])
1160+
1161+
if modules:
11581162
script.newline()
11591163
script.comment('Perform module related changes to the environment.')
11601164

lib/pavilion/unittest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _load_test(self, name: str, platform: str = 'this', host: str = 'this',
313313
del __config_lines
314314

315315
def _quick_test(self, cfg=None, name="quick_test",
316-
build=True, finalize=True):
316+
build=True, finalize=True, purge=False):
317317
"""Create a test run object to work with.
318318
The default is a simple hello world test with the raw scheduler.
319319
@@ -347,7 +347,7 @@ def _quick_test(self, cfg=None, name="quick_test",
347347

348348
cfg = resolve.test_config(cfg, var_man)
349349

350-
test = TestRun(pav_cfg=self.pav_cfg, config=cfg, var_man=var_man)
350+
test = TestRun(pav_cfg=self.pav_cfg, config=cfg, var_man=var_man, purge=purge)
351351
if test.skipped:
352352
# You can't proceed further with a skipped test.
353353
return test

test/tests/mod_wrapper_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_module_purge(self):
319319
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
320320
]
321321

322-
test = self._quick_test(test_cfg)
322+
test = self._quick_test(test_cfg, purge=True)
323323
run_result = test.run()
324324

325325
self.assertEqual(run_result, 0)

0 commit comments

Comments
 (0)