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
This commit is contained in:
janonymous 2015-12-07 21:45:43 +05:30 committed by Alistair Coles
parent b3d6fa1319
commit be54d0c928
2 changed files with 15 additions and 12 deletions

View File

@ -458,16 +458,16 @@ class Test_html_viewer(unittest.TestCase):
self.log_files) self.log_files)
def test_format_source_code(self): def test_format_source_code(self):
nfl_os = '%s:%d(%s)' % (os.__file__[:-1], 136, 'makedirs') osfile = os.__file__.rstrip('c')
self.assertTrue('makedirs' in self.viewer.format_source_code(nfl_os)) nfl_os = '%s:%d(%s)' % (osfile, 136, 'makedirs')
self.assertFalse('makedirsXYZ' in self.assertIn('makedirs', self.viewer.format_source_code(nfl_os))
self.viewer.format_source_code(nfl_os)) self.assertNotIn('makedirsXYZ', self.viewer.format_source_code(nfl_os))
nfl_illegal = '%s:136(makedirs)' % os.__file__ nfl_illegal = '%sc:136(makedirs)' % osfile
self.assertTrue(_('The file type are forbidden to access!') in self.assertIn(_('The file type are forbidden to access!'),
self.viewer.format_source_code(nfl_illegal)) self.viewer.format_source_code(nfl_illegal))
nfl_not_exist = '%s.py:136(makedirs)' % os.__file__ nfl_not_exist = '%s.py:136(makedirs)' % osfile
expected_msg = _('Can not access the file %s.') % os.__file__ expected_msg = _('Can not access the file %s.py.') % osfile
self.assertTrue(expected_msg in self.assertIn(expected_msg,
self.viewer.format_source_code(nfl_not_exist)) self.viewer.format_source_code(nfl_not_exist))

View File

@ -12,7 +12,10 @@ setenv = VIRTUAL_ENV={envdir}
deps = deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-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 passenv = SWIFT_* *_proxy
[testenv:cover] [testenv:cover]