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

[BUG] --reruns breaks yielded fixture #274

Closed
GeorgeAtKistler opened this issue Sep 11, 2024 · 2 comments
Closed

[BUG] --reruns breaks yielded fixture #274

GeorgeAtKistler opened this issue Sep 11, 2024 · 2 comments
Labels

Comments

@GeorgeAtKistler
Copy link

GeorgeAtKistler commented Sep 11, 2024

I have a session scoped fixture which should be run before and after the test session:

import logging
import pytest

@pytest.fixture(scope='session', autouse=True)
def my_session_fixture():
    logging.error("################ Pre ################")
    yield    
    logging.error("################ Post ################")
       

def test_dummy():
    assert 1 == 0

This usually shows the following log:

pytest --log-cli-level=INFO tests.py
============================================== test session starts ==============================================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/me
plugins: rerunfailures-14.0
collected 1 item

tests.py::test_dummy
------------------------------------------------ live log setup -------------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
FAILED                                                                                                    [100%]
----------------------------------------------- live log teardown -----------------------------------------------
ERROR    root:tests.py:8 ################ Post ################


=================================================== FAILURES ====================================================
_________________________________________________ test_dummy __________________________________________________

    def test_dummy():
>       assert 1 == 0
E       assert 1 == 0

tests.py:12: AssertionError
---------------------------------------------- Captured log setup -----------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
--------------------------------------------- Captured log teardown ---------------------------------------------
ERROR    root:tests.py:8 ################ Post ################
============================================ short test summary info ============================================
FAILED tests.py::test_dummy - assert 1 == 0
=============================================== 1 failed in 0.16s ===============================================

How ever, if I use the --reruns parameter, the 2nd part (after the yield) does not get executed (################ Post ################ never gets called):

pytest --log-cli-level=INFO --reruns 1 tests.py
============================================== test session starts ==============================================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/me
plugins: rerunfailures-14.0
collected 1 item

tests.py::test_dummy
------------------------------------------------ live log setup -------------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
RERUN                                                                                                     [100%]
tests.py::test_dummy FAILED                                                                               [100%]

=================================================== FAILURES ====================================================
__________________________________________________ test_dummy ___________________________________________________

    def test_dummy():
>       assert 1 == 0
E       assert 1 == 0

tests.py:12: AssertionError
---------------------------------------------- Captured log setup -----------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
============================================ short test summary info ============================================
FAILED tests.py::test_dummy - assert 1 == 0
========================================== 1 failed, 1 rerun in 0.16s ===========================================
@GeorgeAtKistler
Copy link
Author

Like mentioned in #272 (comment) this seems to be related to the pytest version.
I tested it with 8.1.2 and there it was still ok:

pytest --log-cli-level=INFO --reruns 2 tests.py
======================================================== test session starts ========================================================
platform linux -- Python 3.11.2, pytest-8.1.2, pluggy-1.5.0
rootdir: /tmp
plugins: rerunfailures-14.0
collected 1 item

tests.py::test_dummy
---------------------------------------------------------- live log setup -----------------------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
RERUN                                                                                                                         [100%]
tests.py::test_dummy RERUN                                                                                                    [100%]
tests.py::test_dummy
--------------------------------------------------------- live log teardown ---------------------------------------------------------
ERROR    root:tests.py:8 ################ Post ################
FAILED                                                                                                                        [100%]

============================================================= FAILURES ==============================================================
____________________________________________________________ test_dummy _____________________________________________________________

    def test_dummy():
>       assert 1 == 0
E       assert 1 == 0

tests.py:12: AssertionError
-------------------------------------------------------- Captured log setup ---------------------------------------------------------
ERROR    root:tests.py:6 ################ Pre ################
------------------------------------------------------- Captured log teardown -------------------------------------------------------
ERROR    root:tests.py:8 ################ Post ################
====================================================== short test summary info ======================================================
FAILED tests.py::test_dummy - assert 1 == 0
==================================================== 1 failed, 2 rerun in 0.08s =====================================================

@icemac
Copy link
Contributor

icemac commented Sep 13, 2024

Currently pytest >= 8.2 is not supported, see #267, so I am going to close this issue as invalid in favour of that one.

@icemac icemac closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2024
@icemac icemac added the invalid label Sep 13, 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