Skip to content

Commit

Permalink
Only test if pymongo is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
kormoc committed Nov 25, 2012
1 parent 830e877 commit 3c9c7ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/collectors/mongodb/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
pymongo # workaround for pyflakes issue #13
except ImportError:
pymongo = None

try:
from pymongo import ReadPreference
ReadPreference # workaround for pyflakes issue #13
Expand Down
20 changes: 20 additions & 0 deletions src/collectors/mongodb/test/testmongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
################################################################################


def run_only(func, predicate):
if predicate():
return func
else:
def f(arg):
pass
return f


def run_only_if_pymongo_is_available(func):
try:
import pymongo
pymongo # workaround for pyflakes issue #13
except ImportError:
pymongo = None
pred = lambda: pymongo is not None
return run_only(func, pred)


@run_only_if_pymongo_is_available
class TestMongoDBCollector(CollectorTestCase):
def setUp(self):
config = get_collector_config('MongoDBCollector', {
Expand Down

0 comments on commit 3c9c7ab

Please sign in to comment.