Opened 9 years ago

Closed 8 years ago

#355 closed defect (fixed)

nose and modules with optional library deps

Reported by: Elrond Owned by: Elrond
Priority: minor Milestone: 0.3.3
Component: programming Keywords:
Cc: Parent Tickets:

Description (last modified by Christopher Allan Webber)

During unit tests nose imports every ``*.py`` it finds in the tree.
It does so to search for unit tests there. If the import fails,
this gives an error in the final unit test results.
For GMG this can fail, because some modules import optional
libraries (video for example).

Currently known options:


1. Add hard dependencies again for all optional libraries. Not
   nice, but would solve the problem at hand.
2. Rewrite the affected modules to somehow gracefully handle the
   situation and not error. Not really nice, but acceptable.
3. Change ``runtests.sh`` to call nose in a way, that tests are
   only searched in ``mediagoblin.tests``. This seems the nicest way.



Subtickets

Change History (6)

comment:1 Changed 9 years ago by Elrond

Regarding option 2:
I haven't found an easy way in python to leave module
initialisation early. Like
``try: import bigvideolibrary except ImportError: leave_module_init_now()``.
Of course one can do try:
``import CookCoffeeBase from coffeelib except ImportError: CookCoffeeBase = object``
and create dummies for all imported things.

Regarding option 3:
My quick search a few weeks back did not reveal anything simple
either. I hope someone else is more successful.



comment:2 Changed 9 years ago by Elrond

Update: This affects only ``__init__.py`` and modules imported from
there. Some random ``models.py`` importing say sqlalchemy doesn't
trigger this issues on its own.



comment:3 Changed 9 years ago by Will Kahn-Greene

The original url for this bug was http://bugs.foocorp.net/issues/708 .

comment:4 Changed 8 years ago by Elrond

Giving a path to nosetests can easily prevent most of this problem. It tells it to search only for tests in the given directory, like so:

./runtests.sh $PWD/mediagoblin/tests

We could easily modify runtests.sh to add this argument on its own, if no other relevant args are given.

Do we want that?

Are all our tests going to be in mediagoblin/tests? Or are tests for core plugins going to be in their individual directories? Maybe not, because mediagoblin/tests/__init__.py has some setup code for tests.

What do others think?

(hinted by ShawnRisk)

Last edited 8 years ago by Elrond (previous) (diff)

comment:5 Changed 8 years ago by Elrond

Milestone: 0.3.3
Owner: set to Elrond
Status: acceptedassigned

The above mentioned idea for changing runtests.sh has been implemented by me in 7dec9f92f345df4bb33d399f60c49544c7e60bf6.

In my opinion, we can close this issue. Any vetos? (set milestone to next release, so we revisit it sooner than later for just closing or postponing.)

comment:6 Changed 8 years ago by Christopher Allan Webber

Description: modified (diff)
Resolution: fixed
Status: assignedclosed

Closed.

Note: See TracTickets for help on using tickets.