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

Log captured during setup is displayed 3 times #191

Open
ods opened this issue Mar 25, 2020 · 2 comments
Open

Log captured during setup is displayed 3 times #191

ods opened this issue Mar 25, 2020 · 2 comments
Labels

Comments

@ods
Copy link

ods commented Mar 25, 2020

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 ==========================
@Teemu Teemu added the bug label Aug 25, 2020
@millerthegorilla
Copy link

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
Copy link

hortonew commented Jan 5, 2024

I'm not seeing this issue with the following:

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

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

4 participants