Python和pytest测试

Python和pytest测试,python,pytest,Python,Pytest,我必须使用pytest进行一些测试,但我不知道从哪里开始。 下面是我想测试的一段代码: def print_url_and_id(): for item in movie_link[:100]: print item.contents[1], "The ID of this movie is:", '"' + item.contents[1]['href'][7:16] + '"' 有人能告诉我它的样子吗?你可以这样做: import pytest def para

我必须使用pytest进行一些测试,但我不知道从哪里开始。 下面是我想测试的一段代码:

def print_url_and_id():
    for item in movie_link[:100]:
        print item.contents[1], "The ID of this movie is:", '"' + item.contents[1]['href'][7:16] + '"'

有人能告诉我它的样子吗?

你可以这样做:

import pytest


def parametrized():
    expected_results = ["movie_link_01", "movie_link_02"]
    movie_link = ["movie_link_01", "movie_link_02", "movie_link_03"]
    # you can define your new_movie_link list like this as you have done, but instead of
    # printing it, add it to a this new_movie_link list
    return [(item_1, item_2) for item_1, item_2 in zip(movie_link[:2], expected_results)]


@pytest.mark.parametrize("movie_link, expected", parametrized())
def test_parametrizer(movie_link, expected):
    assert movie_link == expected

您可能应该从深入单元测试过程本身开始,请将您的代码作为代码