issue1035 Override inspect.isclass for python 2.6

This commit is contained in:
TomV 2015-10-07 09:25:12 +01:00
parent 707226298a
commit 88c8dd96f9
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,8 @@
2.8.3.dev 2.8.3.dev
--------- ---------
- fix #1035: collecting tests if test module level obj has __getattr__().
Thanks Suor for the report and Bruno Oliveira / Tom Viner for the PR.
2.8.2 2.8.2
----- -----

View File

@ -4,6 +4,7 @@ import fnmatch
import functools import functools
import py import py
import inspect import inspect
import types
import sys import sys
import pytest import pytest
from _pytest.mark import MarkDecorator, MarkerError from _pytest.mark import MarkDecorator, MarkerError
@ -43,6 +44,14 @@ else:
def _format_args(func): def _format_args(func):
return inspect.formatargspec(*inspect.getargspec(func)) return inspect.formatargspec(*inspect.getargspec(func))
if sys.version_info[:2] == (2, 6):
def isclass(object):
""" Return true if the object is a class. Overrides inspect.isclass for
python 2.6 because it will return True for objects which always return
something on __getattr__ calls (see #1035).
Backport of https://hg.python.org/cpython/rev/35bf8f7a8edc
"""
return isinstance(object, (type, types.ClassType))
def _has_positional_arg(func): def _has_positional_arg(func):
return func.__code__.co_argcount return func.__code__.co_argcount
@ -2137,7 +2146,7 @@ def num_mock_patch_args(function):
def getfuncargnames(function, startindex=None): def getfuncargnames(function, startindex=None):
# XXX merge with main.py's varnames # XXX merge with main.py's varnames
#assert not inspect.isclass(function) #assert not isclass(function)
realfunction = function realfunction = function
while hasattr(realfunction, "__wrapped__"): while hasattr(realfunction, "__wrapped__"):
realfunction = realfunction.__wrapped__ realfunction = realfunction.__wrapped__