3131import os
3232import re
3333import sys
34+ import tempfile
3435from unittest import TextTestRunner
3536
3637import easybuild .tools .build_log
@@ -129,11 +130,22 @@ def test_easystack_invalid_key2(self):
129130 self .assertErrorRegex (EasyBuildError , error_pattern , parse_easystack , test_easystack )
130131
131132 def test_easystack_restore_env_after_each_build (self ):
132- """Test that the build environment is reset for each easystack item"""
133+ """Test that the build environment and tmpdir is reset for each easystack item"""
134+
135+ orig_tmpdir_tempfile = tempfile .gettempdir ()
136+ orig_tmpdir_env = os .getenv ('TMPDIR' )
137+ orig_tmpdir_tempfile_len = len (orig_tmpdir_env .split (os .path .sep ))
138+ orig_tmpdir_env_len = len (orig_tmpdir_env .split (os .path .sep ))
139+
133140 test_es_txt = '\n ' .join ([
134141 "easyconfigs:" ,
135142 " - toy-0.0-gompi-2018a.eb:" ,
136143 " - libtoy-0.0.eb:" ,
144+ # also include a couple of easyconfigs for which a module is already available in test environment,
145+ # see test/framework/modules
146+ " - GCC-7.3.0-2.30" ,
147+ " - FFTW-3.3.7-gompi-2018a" ,
148+ " - foss-2018a" ,
137149 ])
138150 test_es_path = os .path .join (self .test_prefix , 'test.yml' )
139151 write_file (test_es_path , test_es_txt )
@@ -143,10 +155,24 @@ def test_easystack_restore_env_after_each_build(self):
143155 '--easystack' ,
144156 test_es_path
145157 ]
146- stdout = self .eb_main (args , do_build = True , raise_error = True )
158+ stdout = self .eb_main (args , do_build = True , raise_error = True , reset_env = False , redo_init_config = False )
147159 regex = re .compile (r"WARNING Loaded modules detected: \[.*gompi/2018.*\]\n" )
148160 self .assertFalse (regex .search (stdout ), "Pattern '%s' should not be found in: %s" % (regex .pattern , stdout ))
149161
162+ # temporary directory after run should be exactly 2 levels deeper than original one:
163+ # - 1 level added by setting up configuration in EasyBuild main function
164+ # - 1 extra level added by first re-configuration for easystack item
165+ # (because $TMPDIR set by configuration done in main function is retained)
166+ tmpdir_tempfile = tempfile .gettempdir ()
167+ tmpdir_env = os .getenv ('TMPDIR' )
168+ tmpdir_tempfile_len = len (tmpdir_tempfile .split (os .path .sep ))
169+ tmpdir_env_len = len (tmpdir_env .split (os .path .sep ))
170+
171+ self .assertEqual (tmpdir_tempfile_len , orig_tmpdir_tempfile_len + 2 )
172+ self .assertEqual (tmpdir_env_len , orig_tmpdir_env_len + 2 )
173+ self .assertTrue (tmpdir_tempfile .startswith (orig_tmpdir_tempfile ))
174+ self .assertTrue (tmpdir_env .startswith (orig_tmpdir_env ))
175+
150176 def test_missing_easyconfigs_key (self ):
151177 """Test that EasyStack file that doesn't contain an EasyConfigs key will fail with sane error message"""
152178 topdir = os .path .dirname (os .path .abspath (__file__ ))
0 commit comments