Skip to content

How to Control Passive Test Functions? #11020

@Yingqingshan

Description

@Yingqingshan

`import pytest

class TestUser:
@pytest.mark.parametrize("username, password", [("admin", "123456"), ("admin1", "123456")])
def test_login(self, username, password):
print("login")

@pytest.mark.parametrize("username, password", [("admin", "123456"), ("admin1", "123456")])
def test_logout(self, username, password):
    print("logout")

@pytest.mark.parametrize("username, password", [("admin", "123456"), ("admin1", "123456")])
def test_register(self, username, password):
    print("register")

class TestExample:
@pytest.mark.parametrize("username, password", [("admin", "123456"), ("admin1", "123456")])
def test_order(self, username, password):
TestUser().test_login(username, password)

if name == 'main':
pytest.main()
`
How to control that when test_order calls the TestUser test class, only the called test_login test function is executed, and not all test functions under TestUser are executed? Is it possible to use the pytest_collection_modifyitems hook provided by pytest to control the test functions that do not need to execute all test classes?

Now the execution result is as follows:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions