def test_transitive_dependencies(self): filenames = ['a.py', 'b.py', 'a.html', 'a.txt'] deps = { 'a.py': ['b.py', 'a.txt'], 'b.py': ['c.py'], 'c.py': [], 'a.html': [], 'a.txt': [] } expected_deps = dependencies._reachable(deps) with mock.patch('dependencies.python_dependencies', side_effect=lambda x: set(deps.get(x, []))), \ mock.patch('dependencies.html_dependencies', side_effect=lambda x: set(deps.get(x, []))): transitive_deps = dependencies.transitive_dependencies(filenames) self.assertEqual(expected_deps, transitive_deps)
def test_transitive_dependencies(self): filenames = ['a.py', 'b.py', 'a.html', 'a.txt'] deps = { 'a.py': ['b.py', 'a.txt'], 'b.py': ['c.py'], 'c.py': [], 'a.html': [], 'a.txt': [] } expected_deps = dependencies._reachable(deps) with mock.patch('dependencies.python_dependencies', side_effect=lambda x: set(deps.get(x, []))), \ mock.patch('dependencies.html_dependencies', side_effect=lambda x: set(deps.get(x, []))): transitive_deps = dependencies.transitive_dependencies(filenames) self.assertEqual(expected_deps, transitive_deps)
def pytest_collection_modifyitems(session, config, items): """Remove those tests which do not depend on the modified files.""" modified_filenames = get_modified_filenames() if modified_filenames is None: print 'Only git and mercurial are supported. No tests were filtered' return test_filenames = set(str(item.fspath) for item in items) all_deps = dependencies.transitive_dependencies(test_filenames) # item.fspath could be None, so adding it to the list of filenames which we # need to check no matter what. required_filenames = set(['None']) for filename in test_filenames: if (filename in modified_filenames or all_deps[filename].intersection(modified_filenames)): required_filenames.add(filename) new_items = [item for item in items if str(item.fspath) in required_filenames] items[:] = new_items
def pytest_collection_modifyitems(session, config, items): """Remove those tests which do not depend on the modified files.""" modified_filenames = get_modified_filenames() if modified_filenames is None: print 'Only git and mercurial are supported. No tests were filtered' return test_filenames = set(str(item.fspath) for item in items) all_deps = dependencies.transitive_dependencies(test_filenames) # item.fspath could be None, so adding it to the list of filenames which we # need to check no matter what. required_filenames = set(['None']) for filename in test_filenames: if (filename in modified_filenames or all_deps[filename].intersection(modified_filenames)): required_filenames.add(filename) new_items = [ item for item in items if str(item.fspath) in required_filenames ] items[:] = new_items