[TIP] Testing dependencies
C. Titus Brown
ctb at msu.edu
Sun Sep 6 12:00:23 PDT 2009
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
More information about the testing-in-python
mailing list