Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will certain data be sent with changes during parameterization and rerun? #271

Open
TestNovice opened this issue Jul 5, 2024 · 1 comment
Labels

Comments

@TestNovice
Copy link

TestNovice commented Jul 5, 2024

import hashlib

import pytest


def encrypt_password(password):
    """
    使用MD5算法对密码进行加密

    :param password: 明文密码字符串
    :return: 加密后的MD5值,以32位小写十六进制字符串表示
    """
    md5_hash = hashlib.md5()
    # 注意:hashlib.md5()接收的是字节类型,因此如果password是字符串,需要先转换为字节
    md5_hash.update(password.encode('utf-8'))
    return md5_hash.hexdigest()


param_data = {
    "username": "admin",
    "password": "123456"
}


@pytest.mark.flaky(reruns=2, reruns_delay=2)
@pytest.mark.parametrize("source_data", [param_data])
def test_sum_data(source_data):
    source_data["password"] = encrypt_password(source_data["password"])
    print("encrypt_data:", source_data)

    assert False

this result:
Snipaste_2024-07-05_16-24-49

So, does re running not reinitialize some data?

@icemac
Copy link
Contributor

icemac commented Jul 15, 2024

Hi @TestNovice, inside the test function you are changing the values of your param_data dict.
– This is the way Python works.
There is no way to reinitialize the parameters of the function.

@icemac icemac added the invalid label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants