def filterTests(module, testFilter, testNames):
    """
    Filters out all test names that do not belong to the given module or where one name component
    equals the testFilter string.
    """
    filteredNames = []
    for testName in testNames:
        nameComponents = testName.split('.')

        testIsFromModule = module in nameComponents
        hasTestFilter = True
        if testFilter:
            hasTestFilter = testFilter in nameComponents

        if testIsFromModule and hasTestFilter:
            filteredNames.append(testName)

    return filteredNames