<div dir="ltr">Ok, I think I figured out the root of all the problems.<div><br></div><div>First, in setupSysPath we have this:</div><div><br></div><div><div>    sys.path.insert(0, scriptPath)</div></div><div><br></div><div>This basically adds `lldb/packages/Python/lldbsuite/test` to sys.path.</div><div><br></div><div>Then, in the individual tests we write this:</div><div><br></div><div>from lldbtest import *<br></div><div><br></div><div>It finds lldbtest at the above path, and imports it.  But this is *not* the same copy of lldbtest that has already been imported, because that copy was imported as a member of the lldbsuite.test package.  So now we have this module in sys.modules twice.  Once as lldbtest, found by looking in lldbsuite/test since it was in sys.path.  And once as lldbsuite.test.lldbtest, found because lldbsuite was in sys.path, using subpackage resolution.</div><div><br></div><div>I think the fix for all of these problems is to *remove* scriptPath from sys.path.  We shouldn't be mucking with sys.path for stuff in our own test suite.  We should resolve the references explicitly with subpackage references.  For example, even if I don't write __package__ = "lldbsuite.test" in TestMultithreaded.py, I can still fix the problem with the below patch:</div><div><br></div><div>- from lldbtest import *</div><div>+ from lldbsuite.test.lldbtest import *<br></div><div><br></div><div>because now we're referencing the module that has already been imported.  This is the "correct" way to do it, so if we tighten up sys.path, nobody should be able to make this mistake again.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 2, 2015 at 4:32 PM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think what is happening is that when we go through unittest2, the package link is being broken.<div><br></div><div>Inside dotest.py : __package__ = lldbsuite.test</div><div>Inside unittest2.loadTestsFromName : __package__ = unittest2</div><div>Inside TestMultithreaded.py : __package__ = None</div><div><br></div><div>Restoring the link by writing</div><div><br></div><div>__package__ = "lldbsuite.test"</div><div><br></div><div>at the top of TestMultithreaded.py seems to fix the problem, although that really bothersome to have to do that in every single file.  I'm still trying to figure out the proper fix.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 2, 2015 at 3:41 PM Pavel Labath via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: labath<br>
Date: Mon Nov  2 17:39:09 2015<br>
New Revision: 251862<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=251862&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=251862&view=rev</a><br>
Log:<br>
Revert "Remove the __import__ hack of lldbtest_config."<br>
<br>
The hack still seems to be necessary. Putting it back in until we figure out why.<br>
<br>
Modified:<br>
    lldb/trunk/packages/Python/lldbsuite/test/dotest.py<br>
<br>
Modified: lldb/trunk/packages/Python/lldbsuite/test/dotest.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest.py?rev=251862&r1=251861&r2=251862&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/dotest.py?rev=251862&r1=251861&r2=251862&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/dotest.py (original)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/dotest.py Mon Nov  2 17:39:09 2015<br>
@@ -19,11 +19,14 @@ for available options.<br>
 """<br>
<br>
 from __future__ import print_function<br>
+# this module needs to have global visibility, otherwise test cases<br>
+# will import it anew in their local namespace, essentially losing access<br>
+# to all the configuration data<br>
+globals()['lldbtest_config'] = __import__('lldbtest_config')<br>
<br>
 import use_lldb_suite<br>
-import lldbsuite<br>
<br>
-import lldbtest_config<br>
+import lldbsuite<br>
<br>
 import atexit<br>
 import commands<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div></blockquote></div>