Skip to content

Commit

Permalink
Modify the pytest output to include the execution duration for all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jun 12, 2023
1 parent 226d23d commit e9e82f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/tribler/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import platform
import sys
import time
from pathlib import Path
from unittest.mock import MagicMock

Expand Down Expand Up @@ -38,6 +39,15 @@ def pytest_configure(config): # pylint: disable=unused-argument
logging.getLogger('faker.factory').propagate = False


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


@pytest.fixture(name="tribler_root_dir")
def _tribler_root_dir(tmp_path):
return Path(tmp_path)
Expand Down
10 changes: 10 additions & 0 deletions src/tribler/gui/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time

import pytest

Expand Down Expand Up @@ -26,3 +27,12 @@ def pytest_collection_modifyitems(config, items):
for item in items:
if "guitest" in item.keywords:
item.add_marker(skip_guitests)


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

0 comments on commit e9e82f0

Please sign in to comment.