Hi,
I am not using Python and might miss something, but according to my knowledge and as Robert has said:
a) I never heard about any scripting language runtime that allows dynamic code load/unload;
b) All scripting language runtimes load script code, execute all statements that are out of any function and then execute the 'main' function.
Considering the above,
dosomething
connected = obj.Connect(login)
lines are executed on test start before any test method is executed (i.e. even before your first test starts its execution).
connected variable in this case is a global one for the whole test run, it keeps the value returned by the obj.Connect(login) call and exists even between different tests until test run ends.