From c3f4eb6d5788226d6f8b15a94e13ce6523821729 Mon Sep 17 00:00:00 2001 From: Chris Gilling Date: Wed, 26 Mar 2014 09:27:33 -0700 Subject: [PATCH] change try/except to sys.module.get and a conditional --- _pytest/python.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index ecb316104..50eb870b9 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1836,12 +1836,12 @@ def getfuncargnames(function, startindex=None): if startindex is None: startindex = inspect.ismethod(function) and 1 or 0 if realfunction != function: - try: - from mock import DEFAULT + mock_default = sys.modules.get('mock.DEFAULT') + if mock_default: for patching in getattr(function, "patchings", []): if not patching.attribute_name and patching.new is DEFAULT: startindex += 1 - except ImportError: + else: startindex += len(getattr(function, "patchings", [])) function = realfunction argnames = inspect.getargs(py.code.getrawcode(function))[0]