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?