From be54d0c928528cdc1b12e1bcb1614ea8859fae2e Mon Sep 17 00:00:00 2001 From: janonymous Date: Mon, 7 Dec 2015 21:45:43 +0530 Subject: [PATCH] clear pycache and remove all pyc/pyo before starting unit test Delete python bytecode before every test run. Because python creates pyc files during tox runs, certain changes in the tree, like deletes of files, or switching branches, can create spurious errors. Closes-Bug: #1368661 Change-Id: Iedcb400fa3b0417f5bb8e943b17758fcfb4070c6 --- test/unit/common/middleware/test_xprofile.py | 22 ++++++++++---------- tox.ini | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/unit/common/middleware/test_xprofile.py b/test/unit/common/middleware/test_xprofile.py index 7296f69211..720a722311 100644 --- a/test/unit/common/middleware/test_xprofile.py +++ b/test/unit/common/middleware/test_xprofile.py @@ -458,17 +458,17 @@ class Test_html_viewer(unittest.TestCase): self.log_files) def test_format_source_code(self): - nfl_os = '%s:%d(%s)' % (os.__file__[:-1], 136, 'makedirs') - self.assertTrue('makedirs' in self.viewer.format_source_code(nfl_os)) - self.assertFalse('makedirsXYZ' in - self.viewer.format_source_code(nfl_os)) - nfl_illegal = '%s:136(makedirs)' % os.__file__ - self.assertTrue(_('The file type are forbidden to access!') in - self.viewer.format_source_code(nfl_illegal)) - nfl_not_exist = '%s.py:136(makedirs)' % os.__file__ - expected_msg = _('Can not access the file %s.') % os.__file__ - self.assertTrue(expected_msg in - self.viewer.format_source_code(nfl_not_exist)) + osfile = os.__file__.rstrip('c') + nfl_os = '%s:%d(%s)' % (osfile, 136, 'makedirs') + self.assertIn('makedirs', self.viewer.format_source_code(nfl_os)) + self.assertNotIn('makedirsXYZ', self.viewer.format_source_code(nfl_os)) + nfl_illegal = '%sc:136(makedirs)' % osfile + self.assertIn(_('The file type are forbidden to access!'), + self.viewer.format_source_code(nfl_illegal)) + nfl_not_exist = '%s.py:136(makedirs)' % osfile + expected_msg = _('Can not access the file %s.py.') % osfile + self.assertIn(expected_msg, + self.viewer.format_source_code(nfl_not_exist)) class TestStats2(unittest.TestCase): diff --git a/tox.ini b/tox.ini index ac22896de4..fbce200522 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,10 @@ setenv = VIRTUAL_ENV={envdir} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = nosetests {posargs:test/unit} +commands = find . -type f -name "*.py[c|o]" -delete + find . -type d -name "__pycache__" -delete + nosetests {posargs:test/unit} +whitelist_externals = find passenv = SWIFT_* *_proxy [testenv:cover]