Merge pull request #2764 from xuanluong/issue-2758-fix-mark-decorator-equality

[bugfix] Checking MarkDecorator equality returns False for non-MarkDecorator object
This commit is contained in:
Ronny Pfannschmidt 2017-09-09 10:03:49 +02:00 committed by GitHub
commit 25ed4edbc7
3 changed files with 14 additions and 1 deletions

View File

@ -330,7 +330,7 @@ class MarkDecorator:
return self.name # for backward-compat (2.4.1 had this attr)
def __eq__(self, other):
return self.mark == other.mark
return self.mark == other.mark if isinstance(other, MarkDecorator) else False
def __repr__(self):
return "<MarkDecorator %r>" % (self.mark,)

1
changelog/2758.bugfix Normal file
View File

@ -0,0 +1 @@
The equality checking function (``__eq__``) of ``MarkDecorator`` returns ``False`` if one object is not an instance of ``MarkDecorator``.

View File

@ -812,3 +812,15 @@ def test_legacy_transfer():
assert fake_method.fun
# pristine marks dont transfer
assert fake_method.pytestmark == [pytest.mark.fun.mark]
class TestMarkDecorator(object):
@pytest.mark.parametrize('lhs, rhs, expected', [
(pytest.mark.foo(), pytest.mark.foo(), True),
(pytest.mark.foo(), pytest.mark.bar(), False),
(pytest.mark.foo(), 'bar', False),
('foo', pytest.mark.bar(), False)
])
def test__eq__(self, lhs, rhs, expected):
assert (lhs == rhs) == expected