Skip ExtendTestCase if templates directory is missing

The release tarball does not contain the `templates` directory.
Therefore `ExtendTestCase` will fail:

```
======================================================================
ERROR: test_run (unit.utils.test_extend.ExtendTestCase)
[CPU:0.0%|MEM:53.9%]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/unit/utils/test_extend.py", line 40, in test_run
    out = salt.utils.extend.run('test', 'test', 'this description', integration.CODE_DIR, False)
  File "salt/utils/extend.py", line 242, in run
    MODULE_OPTIONS = _fetch_templates(os.path.join(salt_dir, 'templates'))
  File "salt/utils/extend.py", line 76, in _fetch_templates
    for item in os.listdir(src):
FileNotFoundError: [Errno 2] No such file or directory: ' templates'
```

Signed-off-by: Benjamin Drung <benjamin.drung@cloud.ionos.com>
This commit is contained in:
Benjamin Drung 2019-04-03 15:04:20 +02:00
parent 0473683ace
commit e74f78fca6

View file

@ -14,7 +14,7 @@ import shutil
from datetime import date
# Import Salt Testing libs
from tests.support.unit import TestCase
from tests.support.unit import TestCase, skipIf
from tests.support.mock import MagicMock, patch
# Import salt libs
@ -35,6 +35,8 @@ class ExtendTestCase(TestCase):
shutil.rmtree(self.out, True)
os.chdir(self.starting_dir)
@skipIf(not os.path.exists(os.path.join(integration.CODE_DIR, 'templates')),
"Test template directory 'templates/' missing.")
def test_run(self):
with patch('sys.exit', MagicMock):
out = salt.utils.extend.run('test', 'test', 'this description', integration.CODE_DIR, False)