<br><br><div class="gmail_quote">On Sun, Sep 6, 2009 at 3:00 PM, C. Titus Brown <span dir="ltr"><<a href="mailto:ctb@msu.edu">ctb@msu.edu</a>></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>
-> Hi,<br>
<div><div></div><div class="h5">-><br>
-> I am currently working in a small project that has a couple of dependencies.<br>
-><br>
-> The problem is I do not need them directly (no need to import them at any<br>
-> point) because I call those dependencies with subprocess.Popen<br>
-><br>
-> My current approach is to try an import anyway and fail with an error<br>
-> message if it could not import the module:<br>
-><br>
-> try:<br>
-> import dependency_1<br>
-> import dependency_2<br>
-> except Exception, e:<br>
-> print "DependencyError: %s" % e<br>
-><br>
-> Is it better to put this within the tests directory along with the other<br>
-> tests?<br>
-><br>
-> Or maybe have them in both places: one in the main source code and the other<br>
-> 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'd probably trying an import in the main package & 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>