Skip to content

reruns condition evaluates not in real time #161

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

Open
15klli opened this issue Jun 18, 2021 · 2 comments
Open

reruns condition evaluates not in real time #161

15klli opened this issue Jun 18, 2021 · 2 comments

Comments

@15klli
Copy link

15klli commented Jun 18, 2021

  • version: 10.0
  • code
retryBool = True
@pytest.mark.flaky(condition=retryBool,reruns=2)
def test_demo():
    retryBool = False
    assert False

I found that if I set the mark like the above code, It can't stop retry when after the first run. It shows that the condition does not evaluate in real time but before the case was run.

But I think it's better if the condition evaluates in real time, because it let me able to control the retry on runtime. For example, if the number of failed cases reaches a certain number, then retry the following failed cases.

And the@pytest.mark.skipif(condition="bool",reason="xxx") evaluates in real time.

@icemac
Copy link
Contributor

icemac commented Jun 18, 2021

To change the value of the global variable you have to declare it global, otherwise you create a new independent local variable in your test function:

retryBool = True
@pytest.mark.flaky(condition=retryBool,reruns=2)
def test_demo():
    global retryBool
    retryBool = False
    assert False

See https://docs.python.org/3/reference/simple_stmts.html#grammar-token-global-stmt for details about global.

@icemac icemac closed this as completed Jun 18, 2021
@icemac icemac added the invalid label Jun 18, 2021
@15klli
Copy link
Author

15klli commented Jun 18, 2021

Sorry, my Fault. I forgot to add global. But after declaring it global , it also doesn't work.

image

And I refactor this with my PR

@icemac icemac reopened this Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants