Beispiel #1
0
def test_test_groups() -> None:
    """
    The test suite is split into various "groups".
    This test confirms that the groups together contain all tests, and each
    test is collected only once.
    """
    test_groups_path = 'test_groups.yaml'
    if 'pyexecnetcache' in os.getcwd():
        # We are running this from outside the cluster using pytest-xdist, so test_groups.yaml won't be in the current
        # working directory. It will be in /extra
        test_groups_path = os.path.join('extra', test_groups_path)
    else:
        test_groups_path = os.path.join(os.getcwd(), test_groups_path)

    test_group_file = Path(test_groups_path)
    test_group_file_contents = test_group_file.read_text()
    test_groups = yaml.load(test_group_file_contents)['groups']
    test_patterns = []
    for group in test_groups:
        test_patterns += patterns_from_group(group_name=group,
                                             test_groups_path=test_groups_path)

    # Turn this into  a list otherwise we can't cannonically state whether every test was collected _exactly_ once :-)
    tests_to_patterns = defaultdict(list)  # type: Mapping[str, List]
    for pattern in test_patterns:
        tests = _tests_from_pattern(ci_pattern=pattern,
                                    cwd=os.path.dirname(test_groups_path))
        for test in tests:
            tests_to_patterns[test].append(pattern)

    errs = []
    for test_name, patterns in tests_to_patterns.items():
        message = ('Test "{test_name}" will be run once for each pattern in '
                   '{patterns}. '
                   'Each test should be run only once.').format(
                       test_name=test_name,
                       patterns=patterns,
                   )
        if len(patterns) != 1:
            assert len(patterns) != 1, message
            errs.append(message)

    if errs:
        for message in errs:
            log.error(message)
        raise Exception(
            "Some tests are not collected exactly once, see errors.")

    all_tests = _tests_from_pattern(ci_pattern='',
                                    cwd=os.path.dirname(test_groups_path))
    assert tests_to_patterns.keys() - all_tests == set()
    assert all_tests - tests_to_patterns.keys() == set()
Beispiel #2
0
def test_test_groups() -> None:
    """
    The test suite is split into various "groups".
    This test confirms that the groups together contain all tests, and each
    test is collected only once.
    """
    test_group_file = Path('test_groups.yaml')
    test_group_file_contents = test_group_file.read_text()
    test_groups = yaml.load(test_group_file_contents)['groups']
    test_patterns = []
    for group in test_groups:
        test_patterns += patterns_from_group(group_name=group)

    # Turn this into  a list otherwise we can't cannonically state whether every test was collected _exactly_ once :-)
    tests_to_patterns = defaultdict(list)  # type: Mapping[str, List]
    for pattern in test_patterns:
        tests = _tests_from_pattern(ci_pattern=pattern)
        for test in tests:
            tests_to_patterns[test].append(pattern)

    errs = []
    for test_name, patterns in tests_to_patterns.items():
        message = (
            'Test "{test_name}" will be run once for each pattern in '
            '{patterns}. '
            'Each test should be run only once.'
        ).format(
            test_name=test_name,
            patterns=patterns,
        )
        if len(patterns) != 1:
            assert len(patterns) != 1, message
            errs.append(message)

    if errs:
        for message in errs:
            log.error(message)
        raise Exception("Some tests are not collected exactly once, see errors.")

    all_tests = _tests_from_pattern(ci_pattern='')
    assert tests_to_patterns.keys() - all_tests == set()
    assert all_tests - tests_to_patterns.keys() == set()
def test_test_groups() -> None:
    """
    The test suite is split into various "groups".
    This test confirms that the groups together contain all tests, and each
    test is collected only once.
    """
    test_group_file = Path('test_groups.yaml')
    test_group_file_contents = test_group_file.read_text()
    test_groups = yaml.load(test_group_file_contents)['groups']
    test_patterns = []
    for group in test_groups:
        test_patterns += patterns_from_group(group_name=group)

    # Turn this into  a list otherwise we can't cannonically state whether every test was collected _exactly_ once :-)
    tests_to_patterns = defaultdict(list)  # type: Mapping[str, List]
    for pattern in test_patterns:
        tests = _tests_from_pattern(ci_pattern=pattern)
        for test in tests:
            tests_to_patterns[test].append(pattern)

    errs = []
    for test_name, patterns in tests_to_patterns.items():
        message = ('Test "{test_name}" will be run once for each pattern in '
                   '{patterns}. '
                   'Each test should be run only once.').format(
                       test_name=test_name,
                       patterns=patterns,
                   )
        if len(patterns) != 1:
            assert len(patterns) != 1, message
            errs.append(message)

    if errs:
        for message in errs:
            log.error(message)
        raise Exception(
            "Some tests are not collected exactly once, see errors.")

    all_tests = _tests_from_pattern(ci_pattern='')
    assert tests_to_patterns.keys() - all_tests == set()
    assert all_tests - tests_to_patterns.keys() == set()