Skip to content

Commit

Permalink
Make pytest extended logging logic dependent on --verbose flag
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jun 14, 2023
1 parent 2839bf5 commit 8109605
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/tribler/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

import pytest
from _pytest.config import Config

from tribler.core.utilities.network_utils import default_network_utils

Expand All @@ -14,6 +15,7 @@
# was garbage collected. Without the origin tracking, it may be hard to see the test that created the task.
sys.set_coroutine_origin_tracking_depth(10)

enable_extended_logging = False
pytest_start_time = 0 # a time when the test suite started


Expand All @@ -24,6 +26,12 @@ def pytest_configure(config):
logging.getLogger('faker.factory').propagate = False


@pytest.hookimpl
def pytest_cmdline_main(config: Config):
global enable_extended_logging # pylint: disable=global-statement
enable_extended_logging = config.option.verbose > 0


@pytest.hookimpl
def pytest_collection_finish(session):
""" Save the start time of the test suite execution"""
Expand All @@ -40,7 +48,8 @@ def pytest_runtest_protocol(item, log=True, nextitem=None):
yield
duration = time.time() - start_time
total = time.time() - pytest_start_time
print(f' in {duration:.3f}s ({total:.1f}s in total)', end='')
if enable_extended_logging:
print(f' in {duration:.3f}s ({total:.1f}s in total)', end='')


@pytest.fixture
Expand Down

0 comments on commit 8109605

Please sign in to comment.