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

Add information about the total runtime of the test suite. #7485

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='')