[TIP] Testing dependencies

Alfredo Deza arufuredosan at gmail.com
Sun Sep 6 12:05:12 PDT 2009


On Sun, Sep 6, 2009 at 3:00 PM, C. Titus Brown <ctb at msu.edu> wrote:

> On Sun, Sep 06, 2009 at 02:55:31PM -0400, Alfredo Deza wrote:
> -> Hi,
> ->
> -> I am currently working in a small project that has a couple of
> dependencies.
> ->
> -> The problem is I do not need them directly (no need to import them at
> any
> -> point) because I call those dependencies with subprocess.Popen
> ->
> -> My current approach is to try an import anyway and fail with an error
> -> message if it could not import the module:
> ->
> -> try:
> ->     import dependency_1
> ->     import dependency_2
> -> except Exception, e:
> ->     print "DependencyError: %s" % e
> ->
> -> Is it better to put this within the tests directory along with the other
> -> tests?
> ->
> -> Or maybe have them in both places: one in the main source code and the
> other
> -> one in the tests directory?
>
> What problems are you running into with the current approach -- why do
> you feel the need to change?
>
> I'd probably trying an import in the main package & tests, and
> printing a warning if that fails; and then test the real dependency in
> your tests that call subprocess.  This is because there are reasons why
> subprocess might succeed but import might fail.
>
> cheers,
> --t
> --
> C. Titus Brown, ctb at msu.edu


Ah! good catch!

You are right, there might be situations where an import might fail.

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.

Thanks for the advice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/testing-in-python/attachments/20090906/f9fe4355/attachment.htm 


More information about the testing-in-python mailing list