Rename selected collections and objects
Only renames active collection and selected objects:
import bpy
def testFunction():
    selection = bpy.context.selected_objects
    for x in selection:
        x.name = 'test_' + x.name
        x.data.name = 'test_' + x.data.name
    collection = bpy.context.view_layer.active_layer_collection.collection
    if collection.name == 'Master Collection':
        return
    collection.name = 'test_' + collection.name

if __name__ == '__main__':
    testFunction()