-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
The problem:
Pytest uses old-style classes everywhere. E.g.,
class MarkGenerator:
………
class MarkDecorator:
………
This causes unexpected behaviour in some cases. For example, when trying to get an item from a mark, AttributeError
is raised (as in the old-style classes) instead of TypeError
(as in the new-style classes).
The old-style classes are long deprecated, and the modern libraries & young developers do not expect this weird behaviour in their code anymore. This causes errors when trying to integrate pytest with other libraries & frameworks. For instance, in Jinja template engine (pallets/jinja#631); but there may be other cases.
The solution:
It would be nice if all classes would be new-style classes, i.e. explicitly inheriting from object
:
class MarkGenerator(object):
………
class MarkDecorator(object):
………
Possible problems:
This will probably break the compatibility with python < 2.7 (officially 2.6+ is declared for pytest).
Also, in python3, the no-braces syntax is a new normal (again), but causes the new-style classes with implicit inheritance from object
. The 2.7's new-style syntax is supported.
So, explicit mentioning of (object)
may be of use for python2.7 only. Hence, it should be discussed is it worth changing the code for this case.
Notes:
Python 2.7.10.
pytest==3.0.3