Skip to content

Marking subclass affected methods of parent class. #2947

Closed
@namezys

Description

@namezys

I tried to create a class with some test methods with a fixture.
I have a special marker with kwargs that can change behaviour the fixture.
And I want to run this tests with different parameters of this marker.

Unfortunately, all subclass share one method and I every mark affected this method.

Small example:

@pytest.mark.my_marker(status="A")
class TestA(object):

    @pytest.mark.my_marker(status="M")
    def test_method(self, task_context):
        pass

@pytest.mark.my_marker(status="B")
class TestB(TestA):
    pass

In result I have 2 tests:

  • TestA. test_method
  • TestB. test_method

But both test have the same marker with kwargs={"status": "B}

As I understand, pytest.markstore marker in function object and mark method even if it is applied to class.
So it setup markers:

  • my_marker(status="M")
  • my_marker(status="A")
  • my_marker(status="B")

In this case ability to mark method and class simultaneously looks useless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions