Skip to content

MarkDecorator __eq__ override can lead to bad side effects #2758

@astraw38

Description

@astraw38

The MarkDecorator __eq__ method assumes that it will always be compared with another mark. If you do large parametrizations based on lists, then you'll likely run into scenarios where this isn't the case (especially if you do combinations of lists).

Simple example:

import pytest
TEST_DATA = ['a', 'b', 'c', pytest.mark.xfail('d')]
SUBSET_TESTS = [x for x in TEST_DATA if x in ('a', 'b')]

@pytest.mark.parametrize('data', SUBSET_TESTS)
def test_me(data):
     pass

You'll get an error on collection:

    return self.mark == other.mark
E   AttributeError: 'str' object has no attribute 'mark'

This affects sets, lists (including list.index!), anything that checks for equality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions