Skip to content

Commit

Permalink
Add information about the total runtime of the test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jun 13, 2023
1 parent 6d6857e commit c1631de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/tribler/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,33 @@
# 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)

pytest_start_time = 0 # a time when the test suite started

def pytest_configure(config): # pylint: disable=unused-argument

# pylint: disable=unused-argument

def pytest_configure(config):
# Disable logging from faker for all tests
logging.getLogger('faker.factory').propagate = False


@pytest.hookimpl
def pytest_collection_finish(session):
""" Save the start time of the test suite execution"""
# Called after collection has been performed and modified.
global pytest_start_time # pylint: disable=global-statement
pytest_start_time = time.time()


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_protocol(item, log=True, nextitem=None): # pylint: disable=unused-argument
def pytest_runtest_protocol(item, log=True, nextitem=None):
""" Modify the pytest output to include the execution duration for all tests """
# Perform the runtest protocol for a single test item.
start_time = time.time()
yield
duration = time.time() - start_time
print(f' in {duration:.3f}s', end='')
total = time.time() - pytest_start_time
print(f' in {duration:.3f}s ({total:.1f}s in total)', end='')


@pytest.fixture
Expand Down
18 changes: 16 additions & 2 deletions src/tribler/gui/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import pytest

pytest_start_time = 0 # a time when the test suite started


# pylint: disable=unused-argument

def pytest_configure(config): # pylint: disable=unused-argument
# Disable logging from faker for all tests
Expand All @@ -29,10 +33,20 @@ def pytest_collection_modifyitems(config, items):
item.add_marker(skip_guitests)


@pytest.hookimpl
def pytest_collection_finish(session):
""" Save the start time of the test suite execution"""
# Called after collection has been performed and modified.
global pytest_start_time # pylint: disable=global-statement
pytest_start_time = time.time()


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_protocol(item, log=True, nextitem=None): # pylint: disable=unused-argument
def pytest_runtest_protocol(item, log=True, nextitem=None):
""" Modify the pytest output to include the execution duration for all tests """
# Perform the runtest protocol for a single test item.
start_time = time.time()
yield
duration = time.time() - start_time
print(f' in {duration:.3f}s', end='')
total = time.time() - pytest_start_time
print(f' in {duration:.3f}s ({total:.1f}s in total)', end='')

0 comments on commit c1631de

Please sign in to comment.