You added the new cube while still in Edit Mode.
So both meshes are now part of one object - as shown in the Outliner.
You can easily split them into separate objects through
Mesh > Separate > By Loose Parts
You can select the first object in the collection and then go down to the last object and Shift select, this will select all objects that are between the two selected ones(even if their visibillity is set to off).
Choose the face with edge loop select Alt + LMB:
Click the side you want them to propagate, ideally on the edge (the red circle position).
Sometime it won't propagate correctly, the you might need to switch between face and edge select mode until one is working correclty. If none of them work, then their must be some topology issue that cannot treat those ...
What you are trying to do is change the current context. Instead, you should just be overriding the context.
First step for that would be finding the context that you want to use, that would be our VIEW3D REGION for this case, so we can just cycle through all the context screens available till we find VIEW_3D
for area in bpy.context.screen.areas: