<div dir="ltr"><div class="gmail_quote">Hello Mike,<br><div dir="ltr"><br>The reason of the problem is that the class Test was not pushed into the sys.modules.<br>Use one more separate module for that stuff:<div class="Ih2E3d">
<br><b>one.py</b><br>class Test(object):<br></div>    '''just define'''<br>
<br><b>three.py</b><br>
from one import Test<br>
#push one.pyc to sys.modules<div class="Ih2E3d"><br>
<br>if __name__ == '__main__':<br>

    import two<br>

    two.run( Test() )<br>
<br><b>two.py</b><br>def run( a ):<br>    from one import Test<br></div>    #reuse existing Test<div class="Ih2E3d"><br>    print type(a), Test, type(a) == Test<br><br></div>Regards,<br>Alexey<br><br><div class="gmail_quote">
<div><div></div><div class="Wj3C7c">On Sat, Aug 2, 2008 at 5:16 PM, Mike Wyatt <span dir="ltr"><<a href="mailto:mikejohnwyatt@gmail.com" target="_blank">mikejohnwyatt@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c"><div dir="ltr">I have a problem where type comparisons don't work in a second module when unit tests in the first module are run.  In the example below, class Test is declared in one.py.  When one.py is executed, it calls a method in two.py that imports Test from one.py.  The problem is that the Test object passed into the run method is in the "__main__" namespace, while the Test class imported from one.py is in the "one" namespace.  Comparing type(a) and Test returns False, even though they are both Test objects.  How can I tweak these modules so that the type comparison returns True?<br>


<br>I suppose one solution is to redesign my solution to not compare types, but I would still appreciate a solution for my personal knowledge.<br><br>
<b>*** one.py ***</b><br>
class Test(object):<br>
    pass<br>
<br>
if __name__ == '__main__':<br>
    import two<br>
    two.run( Test() )<br><br><b>*** two.py ***<br></b>def run( a ):<br>    from one import Test<br>    print type(a), Test, type(a) == Test<br><b><br>*** Output ***<br></b><class '__main__.Test'> <class 'one.Test'> False<br>


<br></div>
<br></div></div>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br></div>
</div><br></div>