简体   繁体   中英

py.test change order of test inside the test class

I would like to change the order of test execution inside the test class when using @pytest.mark.parametrize fixture.

For example:

@pytest.mark.parametrize("param", ['test1', 'test2'])
class TestForTesting:
    def test_1(self, param):
        print param
    def test_2(self, param):
        print param

In this care py.test will run: test_1 with 'test1', 'test2' parameters and after that test_2 with 'test1', 'test2' parameters.

What I would like to do is to have it running in following order: test_1 with parameter 'test1' and then test_2 with parameter 'test1' and after that test_1 with parameter 'test2' and then test_2 with parameter 'test2'.

Is there any way to do this?

Thanks in advance.

If you don't use parametrize at all but the "good old" way instead, then you get the order that you want in this case:

class BaseTest:
    def test_1(self):
        print self.param
    def test_2(self):
        print self.param

class TestX(BaseTest):
    param = "A"

class TestY(BaseTest):
    param = "B"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM