Esempio n. 1
0
def collect_tests(test_dirs=TEST_PATHS, verbose=False):
    """Return a list of test files and/or tests cases."""
    if test_dirs:
        test_dirs = [
            test_dir for test_dir in test_dirs if os.path.exists(test_dir)
        ]

    if not test_dirs:
        raise IpaControllerException(
            'No test directories found.'
        )

    if verbose:
        plugin = CollectItemsPlugin()
        args = '--collect-only -p no:terminal {}'.format(
            ' '.join(test_dirs)
        )
        cmds = shlex.split(args)
        pytest.main(cmds, plugins=[plugin])

        return plugin.collected.values()
    else:
        tests, descriptions = get_test_files(test_dirs)
        all_tests = list(tests.keys()) + list(descriptions.keys())
        return all_tests
Esempio n. 2
0
def test_utils_duplicate_test_description():
    """Test exception raised if duplicate test description."""
    test_dirs = ['tests/data/tests', 'tests/data/tests4']

    with pytest.raises(IpaUtilsException) as error:
        tests, descriptions = ipa_utils.get_test_files(test_dirs)
    assert ('Duplicate test description file name found: '
            'tests/data/tests4/test_image_desc.yaml, '
            'tests/data/tests/test_image_desc.yaml' in str(error.value))
Esempio n. 3
0
def test_utils_duplicate_files():
    """Test exception raised if duplicate test files exist."""
    test_dirs = ['tests/data/tests', 'tests/data/tests2']

    with pytest.raises(IpaUtilsException) as error:
        tests, descriptions = ipa_utils.get_test_files(test_dirs)
    assert ('Duplicate test file name found: '
            'tests/data/tests2/test_image.py, tests/data/tests/test_image.py'
            in str(error.value))
Esempio n. 4
0
def test_utils_file_description_overlap():
    """Test exception raised if test file and test description share name."""
    test_dirs = ['tests/data/tests3']

    with pytest.raises(IpaUtilsException) as error:
        tests, descriptions = ipa_utils.get_test_files(test_dirs)
    assert (
        'Test description name matches test file: '
        'tests/data/tests3/test_image.yaml, tests/data/tests3/test_image.py'
        in str(error.value))