Skip to content

When selecting tests based on node id's, optimize setup_module() and teardown_module if the tests belong to the same module #3358

Description

@shreyashah

Following is the structure of my test script:

test_a.py
    Class Test_A:
        test_one()
        test_two()
        test_three()
        test_four()
    Class Test_B:
        test_one()
        test_five()
        test_six()

If I want to run as:

pytest test_a.py::Test_A::test_one   test_a.py::Test_B::test_five

then, setup_module() and teardown_module is run twice because the collection has assumed the node id's belong to different module. However, in this case I don't want to use -k option because I have a bunch of test cases from different classes but from the same script to be selected and the function names could be same in different classes.

Is there a way we can have collection hook to figure out if the node id's specified on the cmd line belong to the same module or same class and if yes, execute setup_module, setup_class, teardown_class and teardown_module only once?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions