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

[bugfix] Checking MarkDecorator equality returns False for non-MarkDecorator object #2764

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion _pytest/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def markname(self):
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,)
Expand Down
1 change: 1 addition & 0 deletions changelog/2758.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The equality checking function (``__eq__``) of ``MarkDecorator`` returns ``False`` if one object is not an instance of ``MarkDecorator``.
12 changes: 12 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,15 @@ def fake_method(self):
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