Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for updates to inspect module #1117

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: false
language: python
python:
- 2.6
Expand All @@ -7,8 +8,9 @@ python:
- 3.4
- 3.5
- pypy
- nightly
install:
- pip uninstall -y nose
- pip install -r requirements.txt --use-mirrors
- pip install -r requirements.txt
script:
- python setup.py build_tests || python setup.py egg_info; python selftest.py
16 changes: 14 additions & 2 deletions nose/plugins/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ def addPlugin(self, plugin, call):
"""
meth = getattr(plugin, call, None)
if meth is not None:
if call == 'loadTestsFromModule' and \
len(inspect.getargspec(meth)[0]) == 2:
try:
sig = inspect.signature(meth)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]
arg_len = len(args)
if hasattr(meth, '__self__'):
arg_len += 1
except AttributeError:
arg_len = len(inspect.getargspec(meth)[0])
if call == 'loadTestsFromModule' and arg_len == 2:
orig_meth = meth
meth = lambda module, path, **kwargs: orig_meth(module)
self.plugins.append((plugin, meth))
Expand Down Expand Up @@ -153,6 +164,7 @@ def generate(self, *arg, **kw):
if result is not None:
for r in result:
yield r

except (KeyboardInterrupt, SystemExit):
raise
except:
Expand Down
29 changes: 24 additions & 5 deletions nose/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,35 @@ def try_run(obj, names):
if type(obj) == types.ModuleType:
# py.test compatibility
if isinstance(func, types.FunctionType):
args, varargs, varkw, defaults = \
inspect.getargspec(func)
try:
sig = inspect.signature(func)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]
except AttributeError:
args, varargs, varkw, defaults = \
inspect.getargspec(func)

else:
# Not a function. If it's callable, call it anyway
if hasattr(func, '__call__') and not inspect.ismethod(func):
func = func.__call__
try:
args, varargs, varkw, defaults = \
inspect.getargspec(func)
args.pop(0) # pop the self off
try:
sig = inspect.signature(func)
bl = set([inspect.Parameter.VAR_KEYWORD,
inspect.Parameter.VAR_POSITIONAL,
inspect.Parameter.KEYWORD_ONLY])
args = [k for k, v in sig.parameters.items()
if v.kind not in bl]

except AttributeError:
args, varargs, varkw, defaults = \
inspect.getargspec(func)
# signature never returns it
timgates42 marked this conversation as resolved.
Show resolved Hide resolved
args.pop(0) # pop the self off
except TypeError:
raise TypeError("Attribute %s of %r is not a python "
"function. Only functions or callables"
Expand Down