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

@retry_endpoint doesn't worth with pytest.mark.parametrize #740

Open
adrinjalali opened this issue Mar 4, 2022 · 0 comments
Open

@retry_endpoint doesn't worth with pytest.mark.parametrize #740

adrinjalali opened this issue Mar 4, 2022 · 0 comments
Labels

Comments

@adrinjalali
Copy link
Contributor

Imagine the following test:

@retry_endpoint
@pytest.mark.parametrize("test", [1, 2])
def test_name_org_deprecation_warning(test):
    print(test)
    api = HfApi(endpoint=ENDPOINT_STAGING)
    token = api.login(username=USER, password=PASS)
    REPO_NAME = repo_name("crud")

    args = [
        ("create_repo", {}),
        ("update_repo_visibility", {"private": False}),
        ("delete_repo", {}),
    ]

    getattr(api, method)(
        name=REPO_NAME, token=token, repo_type=REPO_TYPE_MODEL, **kwargs
    )

It would fail with:

args = (), kwargs = {}, retry_count = 1

    def decorator(*args, **kwargs):
        retry_count = 1
        while retry_count < number_of_tries:
            try:
>               return function(*args, **kwargs)
E               TypeError: test_name_org_deprecation_warning() missing 1 required positional argument: 'test'

Switching the decorators:

@pytest.mark.parametrize("test", [1, 2])
@retry_endpoint
def test_name_org_deprecation_warning(test):
    print(test)
    api = HfApi(endpoint=ENDPOINT_STAGING)
    token = api.login(username=USER, password=PASS)
    REPO_NAME = repo_name("crud")

    args = [
        ("create_repo", {}),
        ("update_repo_visibility", {"private": False}),
        ("delete_repo", {}),
    ]

    getattr(api, method)(
        name=REPO_NAME, token=token, repo_type=REPO_TYPE_MODEL, **kwargs
    )

would result pytest --collect-only to fail with:

In decorator: function uses no argument 'test'

cc @muellerzr who I think has worked on the decorator.

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

1 participant