Teemu / pytest-sugar

a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly)
Other
1.3k stars 73 forks source link

Log captured during setup is displayed 3 times #191

Open ods opened 4 years ago

ods commented 4 years ago

Test file

import logging
import pytest

@pytest.fixture
def fixture():
    logging.warning('Warning in fixture')

def test_nothing(fixture):
    pass

Output with pytest-sugar

$ pytest -r P test.py 
Test session starts (platform: darwin, Python 3.8.2, pytest 5.3.5, pytest-sugar 0.9.2)
rootdir: /Users/ods/work/sugar-dup-log
plugins: sugar-0.9.2
collecting ... 
 test.py ✓                                             100% ██████████
=============================== PASSES ===============================
____________________________ test_nothing ____________________________
------------------------- Captured log setup -------------------------
WARNING  root:test.py:6 Warning in fixture
____________________________ test_nothing ____________________________
------------------------- Captured log setup -------------------------
WARNING  root:test.py:6 Warning in fixture
____________________________ test_nothing ____________________________
------------------------- Captured log setup -------------------------
WARNING  root:test.py:6 Warning in fixture

Results (0.02s):
       1 passed

Output with pytest-sugar

$ pytest -r P -p no:sugar test.py 
======================== test session starts =========================
platform darwin -- Python 3.8.2, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /Users/ods/work/sugar-dup-log
collected 1 item                                                     

test.py .                                                      [100%]

=============================== PASSES ===============================
____________________________ test_nothing ____________________________
------------------------- Captured log setup -------------------------
WARNING  root:test.py:6 Warning in fixture
========================= 1 passed in 0.01s ==========================
millerthegorilla commented 2 years ago

this is probably the same fault that is reported in #222 . I have just started using pytest-sugar and when I pytest with any combination of the -r flag, I get output three times...

import pytest
class Test:
    @pytest.fixture()
    def setUp(self):
        print("setup")
        yield "resource"
        print("teardown")

    def test_that_depends_on_resource(self, setUp):
        print("testing {}".format(setUp))

and I get:

pytest tests/ -rA
(Linux uses --headless by default. To override, use --headed / --gui. For Xvfb mode instead, use --xvfb. Or hide this info with --headless.)
Test session starts (platform: linux, Python 3.10.5, pytest 7.1.2, pytest-sugar 0.9.5)
Using --randomly-seed=1102316951
rootdir: /var/home/XXX/src/test_tests/django_test
plugins: ordering-0.6, metadata-2.0.2, forked-1.4.0, html-2.0.1, rerunfailures-10.2, randomly-3.12.0, mock-3.8.2, django-4.5.2, cov-3.0.0, bdd-6.0.1, xdist-2.5.0, seleniumbase-3.5.11, sugar-0.9.5
collecting ... 
 tests/features/test_test.py ✓                                   100% ██████████
==================================== PASSES ====================================
______________________ Test.test_that_depends_on_resource ______________________
---------------------------- Captured stdout setup -----------------------------
setup
______________________ Test.test_that_depends_on_resource ______________________
---------------------------- Captured stdout setup -----------------------------
setup
----------------------------- Captured stdout call -----------------------------
testing resource
______________________ Test.test_that_depends_on_resource ______________________
---------------------------- Captured stdout setup -----------------------------
setup
----------------------------- Captured stdout call -----------------------------
testing resource
--------------------------- Captured stdout teardown ---------------------------
teardown
=========================== short test summary info ============================
PASSED tests/features/test_test.py::Test::test_that_depends_on_resource
PASSED tests/features/test_test.py::Test::test_that_depends_on_resource
PASSED tests/features/test_test.py::Test::test_that_depends_on_resource

Results (0.03s):
       1 passed

and

pytest tests/ -rA -p no:sugar
(Linux uses --headless by default. To override, use --headed / --gui. For Xvfb mode instead, use --xvfb. Or hide this info with --headless.)
============================= test session starts ==============================
platform linux -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0
Using --randomly-seed=4284594808
rootdir: /var/home/XXX/src/test_tests/django_test
plugins: ordering-0.6, metadata-2.0.2, forked-1.4.0, html-2.0.1, rerunfailures-10.2, randomly-3.12.0, mock-3.8.2, django-4.5.2, cov-3.0.0, bdd-6.0.1, xdist-2.5.0, seleniumbase-3.5.11
collected 1 item                                                               

tests/features/test_test.py .                                            [100%]

==================================== PASSES ====================================
______________________ Test.test_that_depends_on_resource ______________________
---------------------------- Captured stdout setup -----------------------------
setup
----------------------------- Captured stdout call -----------------------------
testing resource
--------------------------- Captured stdout teardown ---------------------------
teardown
=========================== short test summary info ============================
PASSED tests/features/test_test.py::Test::test_that_depends_on_resource
============================== 1 passed in 0.03s ===============================

.... :(

hortonew commented 9 months ago

I'm not seeing this issue with the following:

python 3.11.2 pytest==7.4.4 pytest-sugar==0.9.7