diff --git a/_pytest/mark.py b/_pytest/mark.py index 74473a9d7..d9af0ffaa 100644 --- a/_pytest/mark.py +++ b/_pytest/mark.py @@ -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 "" % (self.mark,) diff --git a/changelog/2758.bugfix b/changelog/2758.bugfix new file mode 100644 index 000000000..12e4046b8 --- /dev/null +++ b/changelog/2758.bugfix @@ -0,0 +1 @@ +The equality checking function (``__eq__``) of ``MarkDecorator`` returns ``False`` if one object is not an instance of ``MarkDecorator``. \ No newline at end of file diff --git a/testing/test_mark.py b/testing/test_mark.py index 4c495fde0..ae070f3a0 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -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