On Thu, Oct 31, 2013 at 12:15 AM, <[email protected]> wrote: > Author: rjollos > Date: Thu Oct 31 07:15:42 2013 > New Revision: 1537391 > > URL: http://svn.apache.org/r1537391 > Log: > 0.8dev: Remove unnecessary `env_path` variable (path is stored at > `env.path`). Use consistent naming for temp dirs. > > Modified: > bloodhound/trunk/bloodhound_multiproduct/tests/env.py > bloodhound/trunk/bloodhound_multiproduct/tests/model.py > bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py > > Modified: bloodhound/trunk/bloodhound_multiproduct/tests/env.py > URL: > http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/env.py?rev=1537391&r1=1537390&r2=1537391&view=diff > > ============================================================================== > --- bloodhound/trunk/bloodhound_multiproduct/tests/env.py (original) > +++ bloodhound/trunk/bloodhound_multiproduct/tests/env.py Thu Oct 31 > 07:15:42 2013 > @@ -164,7 +164,7 @@ class MultiproductTestCase(unittest.Test > self.env = env = EnvironmentStub(**kwargs) > if create_folder: > if path is None: > - env.path = tempfile.mkdtemp('bh-product-tempenv') > + env.path = tempfile.mkdtemp(prefix='bh-product-tempenv-') > else: > env.path = path > if not os.path.exists(path): > > Modified: bloodhound/trunk/bloodhound_multiproduct/tests/model.py > URL: > http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/model.py?rev=1537391&r1=1537390&r2=1537391&view=diff > > ============================================================================== > --- bloodhound/trunk/bloodhound_multiproduct/tests/model.py (original) > +++ bloodhound/trunk/bloodhound_multiproduct/tests/model.py Thu Oct 31 > 07:15:42 2013 > @@ -41,7 +41,7 @@ class ProductTestCase(unittest.TestCase) > > def setUp(self): > self.env = EnvironmentStub(enable=['trac.*', 'multiproduct.*']) > - self.env.path = tempfile.mkdtemp('bh-product-tempenv') > + self.env.path = tempfile.mkdtemp(prefix='bh-product-tempenv-') > > self.mpsystem = MultiProductSystem(self.env) > try: > > Modified: bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py > URL: > http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py?rev=1537391&r1=1537390&r2=1537391&view=diff > > ============================================================================== > --- bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py (original) > +++ bloodhound/trunk/bloodhound_multiproduct/tests/upgrade.py Thu Oct 31 > 07:15:42 2013 > @@ -53,12 +53,12 @@ TABLES_WITH_PRODUCT_FIELD = ( > > class EnvironmentUpgradeTestCase(unittest.TestCase): > def setUp(self, options=()): > - self.env_path = tempfile.mkdtemp('multiproduct-tempenv') > - self.env = Environment(self.env_path, create=True, > options=options) > + env_path = tempfile.mkdtemp(prefix='bh-product-tempenv-') > + self.env = Environment(env_path, create=True, options=options) > DummyPlugin.version = 1 > > def tearDown(self): > - shutil.rmtree(self.env_path) > + shutil.rmtree(self.env.path) > > def test_can_upgrade_environment_with_multi_product_disabled(self): > self.env.upgrade() > @@ -423,11 +423,11 @@ class EnvironmentUpgradeTestCase(unittes > def _update_config(self, section, key, value): > self.env.config.set(section, key, value) > self.env.config.save() > - self.env = Environment(self.env_path) > + self.env = Environment(self.env.path) > > def _create_file_with_content(self, content): > filename = str(uuid.uuid4())[:6] > - path = os.path.join(self.env_path, filename) > + path = os.path.join(self.env.path, filename) > with open(path, 'wb') as f: > f.write(content) > return path >
In the tearDown function of many TestCases I see the following: self.env = self.global_env = None In most cases it is the last line of code in the tearDown method. Does anyone know the purpose of this? The test fixture will be created for each method that is executed, so I can't see a reason for needing to perform any reset on the attributes. The reason I care about this is that I'm working on adding a cleanup method (via TestCase.addCleanup) to bloodhound_multiproduct.tests.env:MultiproductTestCase._setup_test_env that removes the temporary environment directories after the test run completes. env.path is needed, and if env is set to None in the tearDown method, then the cleanup function will throw an exception.
