2021年3月18日星期四

In pytest, how to run against different ip for cases with different marks or name patterns

I have a question here. I am using Pytest. I have two cases with mark and name as:

1)

@pytest.mark.ip1

def test_ip1_actions()

...  

    @pytest.mark.ip2

    def test_ip2_actions()

    ...

    what I want is:

    if the mark is "ip1", then I will run the test against 1st ip - 192.168.2.23;if the mark is "ip2", then the case should run against 2nd ip - 192.168.2.100

    or:

    based on the name, if case name contains "ip1", it will run against 1st ip; if case name contains "ip2", then run against 2nd ip.

    In fact I have many cases to run against 2 ips, not only 2. and the ip information (as well some other information of the two hosts) are written in an json file. So I would like to find out a general and simple solution.

    I tried but didn't get it.

    I thought maybe do something in the conftest.py file? for example, before the case running, judge the mark or the name? But don't know how to handle.

    Looking forward to your advice, to my first question in stackoverflow! :)

    thanks very much!

    https://stackoverflow.com/questions/66701557/in-pytest-how-to-run-against-different-ip-for-cases-with-different-marks-or-nam March 19, 2021 at 09:56AM

    没有评论:

    发表评论