<br><br><div class="gmail_quote">On Sun, Sep 6, 2009 at 3:00 PM, C. Titus Brown <span dir="ltr">&lt;<a href="mailto:ctb@msu.edu">ctb@msu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Sun, Sep 06, 2009 at 02:55:31PM -0400, Alfredo Deza wrote:<br>
-&gt; Hi,<br>
<div><div></div><div class="h5">-&gt;<br>
-&gt; I am currently working in a small project that has a couple of dependencies.<br>
-&gt;<br>
-&gt; The problem is I do not need them directly (no need to import them at any<br>
-&gt; point) because I call those dependencies with subprocess.Popen<br>
-&gt;<br>
-&gt; My current approach is to try an import anyway and fail with an error<br>
-&gt; message if it could not import the module:<br>
-&gt;<br>
-&gt; try:<br>
-&gt;     import dependency_1<br>
-&gt;     import dependency_2<br>
-&gt; except Exception, e:<br>
-&gt;     print &quot;DependencyError: %s&quot; % e<br>
-&gt;<br>
-&gt; Is it better to put this within the tests directory along with the other<br>
-&gt; tests?<br>
-&gt;<br>
-&gt; Or maybe have them in both places: one in the main source code and the other<br>
-&gt; one in the tests directory?<br>
<br>
</div></div>What problems are you running into with the current approach -- why do<br>
you feel the need to change?<br>
<br>
I&#39;d probably trying an import in the main package &amp; tests, and<br>
printing a warning if that fails; and then test the real dependency in<br>
your tests that call subprocess.  This is because there are reasons why<br>
subprocess might succeed but import might fail.<br>
<br>
cheers,<br>
--t<br>
<font color="#888888">--<br>
C. Titus Brown, <a href="mailto:ctb@msu.edu">ctb@msu.edu</a></font></blockquote><div><br>Ah! good catch!<br>
<br>
You are right, there might be situations where an import might fail.<br>
<br>
The reasoning behind my question is because I have not run into
anything similar  and wanted to avoid an uncommon way of dealing with
it.<br>
<br>
Thanks for the advice <br></div></div><br>