pytest-rerunfailures icon indicating copy to clipboard operation
pytest-rerunfailures copied to clipboard

reruns condition evaluates not in real time

Open 15klli opened this issue 4 years ago • 2 comments

  • 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.

15klli avatar Jun 18 '21 04:06 15klli

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 avatar Jun 18 '21 06:06 icemac

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

15klli avatar Jun 18 '21 09:06 15klli