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

Add support for pytest-rerunfailures #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

john-dupuy
Copy link

Aims to address: pytest-dev/pytest-rerunfailures#109.

Consider the following test case:

import pytest
import random

from pytest_lazyfixture import lazy_fixture


@pytest.fixture
def f_payload():
    yield random.randint(1, 100)


@pytest.mark.parametrize("payload", [lazy_fixture("f_payload")])
def test_lazy_fixture(payload):
    print(f"randomInt: {payload}")
    assert False


def test_without_lazy_fixture(f_payload):
    print(f"randomInt: {f_payload}")
    assert False

Running these yields (with lazy_fixture from master):

$ pytest -k 'test_lazy_fixture' --reruns 1
============================================================================ test session starts ============================================================================
...                                                                                                                      

tests/_internal/test_lazy_fixtures.py::test_lazy_fixture[f_payload] RERUN                                                                                             [ 50%]
tests/_internal/test_lazy_fixtures.py::test_lazy_fixture[f_payload] FAILED                                                                                            [ 50%]
_______________________________________________________________________ test_lazy_fixture[f_payload] ________________________________________________________________________
tests/_internal/test_lazy_fixtures.py:15: in test_lazy_fixture
    assert False
E   assert False
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 48
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 48

tests/_internal/test_lazy_fixtures.py::test_without_lazy_fixture RERUN                                                                                                [100%]
tests/_internal/test_lazy_fixtures.py::test_without_lazy_fixture FAILED                                                                                               [100%]
_________________________________________________________________________ test_without_lazy_fixture _________________________________________________________________________
tests/_internal/test_lazy_fixtures.py:20: in test_without_lazy_fixture
    assert False
E   assert False
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 8
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 89

------------------------------------------------- generated xml file: /home/john/planet/repos/qe/cdp-e2e/output/results.xml -------------------------------------------------
-------------------------------------------- generated html file: file:///home/john/planet/repos/qe/cdp-e2e/output/results.html ---------------------------------------------
========================================================================== short test summary info ==========================================================================
FAILED tests/_internal/test_lazy_fixtures.py::test_lazy_fixture[f_payload] - assert False
FAILED tests/_internal/test_lazy_fixtures.py::test_without_lazy_fixture - assert False
================================================================ 2 failed, 609 deselected, 2 rerun in 0.43s =================================================================

Note the value 48 is repeated in test_lazy_fixture. This is because the lazy fixtures get resolved once and they have no notion of a "retry".

With this PR, the result is:

tests/_internal/test_lazy_fixtures.py::test_lazy_fixture[f_payload] RERUN                                                                                             [ 50%]
tests/_internal/test_lazy_fixtures.py::test_lazy_fixture[f_payload] FAILED                                                                                            [ 50%]
_______________________________________________________________________ test_lazy_fixture[f_payload] ________________________________________________________________________
tests/_internal/test_lazy_fixtures.py:15: in test_lazy_fixture
    assert False
E   assert False
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 72
--------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
randomInt: 77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant