Skip to content

Commit

Permalink
Merge pull request #6620 from kozlovsky/fix/warnings_in_tests
Browse files Browse the repository at this point in the history
Remove spam in pytest output
  • Loading branch information
kozlovsky authored Dec 3, 2021
2 parents 87465a0 + 0ff670e commit d49c83a
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 28 deletions.
21 changes: 20 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[pytest]
timeout = 5
log_level = DEBUG
log_level = INFO
log_cli_format = %(asctime)s %(levelname)s %(message)s
markers =
guitest:Tests for GUI. Skipped by default, use --guitests option to enable them
tunneltest:Slow tests for tunnels. Skipped by default, use --tunneltests option to enable them
enable_https:Use HTTPS instead of HTTP in marked tests
api_key:Used by rest_manager fixture to inject api_key value

filterwarnings =
ignore:Passing field metadata as a keyword arg is deprecated:DeprecationWarning:marshmallow
ignore:Passing field metadata as keyword arguments is deprecated:DeprecationWarning:marshmallow
ignore:The 'default' argument to fields is deprecated:DeprecationWarning:marshmallow
ignore:The 'missing' attribute of fields is deprecated:DeprecationWarning:marshmallow
ignore:"@coroutine" decorator is deprecated since Python 3.8, use "async def" instead:DeprecationWarning:asynctest
ignore:Bare functions are deprecated, use async ones:DeprecationWarning:aiohttp
ignore:returning HTTPException object is deprecated:DeprecationWarning:aiohttp
ignore:Flags not at the start of the expression:DeprecationWarning:pyqtgraph
ignore:Parsing of hex strings that do not start with:DeprecationWarning:pyqtgraph
ignore:The parser module is deprecated:DeprecationWarning:pony
ignore:The symbol module is deprecated:DeprecationWarning:pony
ignore:the imp module is deprecated in favour of importlib:DeprecationWarning:pywintypes
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def test_process_payload_update_type(metadata_store):
assert updated_node2.metadata_type == CHANNEL_TORRENT


class TestException(Exception):
class ThreadedTestException(Exception):
pass


Expand All @@ -464,10 +464,10 @@ async def test_run_threaded(metadata_store):
def f1(a, b, *, c, d):
if a == 1 and b == 2 and c == 3 and d == 4:
return threading.get_ident()
raise TestException('test exception')
raise ThreadedTestException('test exception')

result = await metadata_store.run_threaded(f1, 1, 2, c=3, d=4)
assert result != thread_id

with pytest.raises(TestException, match='^test exception$'):
with pytest.raises(ThreadedTestException, match='^test exception$'):
await metadata_store.run_threaded(f1, 1, 2, c=5, d=6)
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from pony.orm import db_session

from tribler_core.components.metadata_store.remote_query_community.remote_query_community import RemoteQueryCommunity
from tribler_core.components.popularity.community.payload import TorrentsHealthPayload
from tribler_core.components.popularity.community.version_community_mixin import VersionCommunityMixin
from tribler_core.components.metadata_store.remote_query_community.remote_query_community import RemoteQueryCommunity
from tribler_core.utilities.unicode import hexlify


Expand Down Expand Up @@ -78,7 +78,7 @@ def select_torrents_to_gossip(torrents, include_popular=True, include_random=Tru
if include_random:
rest = alive - popular
count = min(PopularityCommunity.GOSSIP_RANDOM_TORRENT_COUNT, len(rest))
rand = set(random.sample(rest, count))
rand = set(random.sample(list(rest), count))

return popular, rand

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pytestmark = pytest.mark.asyncio


class TestException(Exception):
class ComponentTestException(Exception):
pass


Expand Down Expand Up @@ -125,7 +125,7 @@ async def run(self):
await self.require_component(ComponentA)

async def shutdown(self):
raise TestException
raise ComponentTestException

session = Session(tribler_config, [ComponentA(), ComponentB()])
with session:
Expand All @@ -136,7 +136,7 @@ async def shutdown(self):

assert not a.unused_event.is_set()

with pytest.raises(TestException):
with pytest.raises(ComponentTestException):
await session.shutdown()

for component in a, b:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from random import sample
from random import choice

from ipv8.messaging.anonymization.tunnel import PEER_FLAG_EXIT_BT
from ipv8.peerdiscovery.discovery import DiscoveryStrategy
Expand Down Expand Up @@ -63,6 +63,6 @@ def take_step(self):
exit_count = len(exit_peers)
ratio = 1.0 - exit_count / peer_count # Peer count is > 0 per definition
if ratio < self.golden_ratio:
self.overlay.network.remove_peer(sample(exit_peers, 1)[0])
self.overlay.network.remove_peer(choice(list(exit_peers)))
elif ratio > self.golden_ratio:
self.overlay.network.remove_peer(sample(set(self.overlay.get_peers()) - exit_peers, 1)[0])
self.overlay.network.remove_peer(choice(list(set(self.overlay.get_peers()) - exit_peers)))
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ async def on_http_request(self, source_address, payload, circuit_id):

writer = None
try:
with async_timeout.timeout(10):
async with async_timeout.timeout(10):
self.logger.debug("Opening TCP connection to %s", payload.target)
reader, writer = await open_connection(*payload.target)
writer.write(payload.request)
Expand Down
4 changes: 2 additions & 2 deletions src/tribler-gui/tribler_gui/dialogs/dialogcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def on_main_window_resize(self):
self.dialog_widget.setFixedWidth(self.width() - self.left_right_margin)
self.dialog_widget.move(
QPoint(
self.geometry().center().x() - self.dialog_widget.geometry().width() / 2,
self.geometry().center().y() - self.dialog_widget.geometry().height() / 2,
int(self.geometry().center().x() - self.dialog_widget.geometry().width() / 2),
int(self.geometry().center().y() - self.dialog_widget.geometry().height() / 2),
)
)
except RuntimeError:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-gui/tribler_gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def sigint_handler(*_):
self.resize(size)

center = QApplication.desktop().availableGeometry(self).center()
screen_center_pos = QPoint(center.x() - self.width() / 2, center.y() - self.height() / 2)
screen_center_pos = QPoint(int(center.x() - self.width() / 2), int(center.y() - self.height() / 2))
pos = self.gui_settings.value("pos", screen_center_pos)

if not QApplication.desktop().availableGeometry(self).intersects(QRect(pos, self.size())):
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-gui/tribler_gui/widgets/lazytableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update_position(self):

x = parent_rect.width() / 2 - self.width() / 2
y = parent_rect.height() / 2 - self.height() / 2
self.setGeometry(x, y, self.width(), self.height())
self.setGeometry(int(x), int(y), self.width(), self.height())

def resizeEvent(self, event):
super().resizeEvent(event)
Expand Down
12 changes: 6 additions & 6 deletions src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def get_indicator_rect(rect):
r = rect
indicator_border = 1
indicator_side = (r.height() if r.width() > r.height() else r.width()) - indicator_border * 2
y = r.top() + (r.height() - indicator_side) / 2
y = int(r.top() + (r.height() - indicator_side) / 2)
x = r.left() + indicator_border
w = indicator_side
h = indicator_side
Expand Down Expand Up @@ -401,7 +401,7 @@ def draw_title_and_tags(self, painter: QPainter, option: QStyleOptionViewItem,
cur_tag_x = option.rect.x() + 6
cur_tag_y += TAG_HEIGHT + 10

edit_rect = QRect(cur_tag_x + 4, cur_tag_y, TAG_HEIGHT, TAG_HEIGHT)
edit_rect = QRect(int(cur_tag_x + 4), int(cur_tag_y), int(TAG_HEIGHT), int(TAG_HEIGHT))
index.model().edit_tags_rects[index] = edit_rect

if edit_tags_button_hovered:
Expand Down Expand Up @@ -624,8 +624,8 @@ def paint(self, painter, rect, index, toggled=False, hover=False):

painter.save()

x = rect.x() + (rect.width() - self._width) / 2
y = rect.y() + (rect.height() - self._height) / 2
x = int(rect.x() + (rect.width() - self._width) / 2)
y = int(rect.y() + (rect.height() - self._height) / 2)

offset = self._end_offset[toggled]()
p = painter
Expand Down Expand Up @@ -664,7 +664,7 @@ def paint(self, painter, rect, index, toggled=False, hover=False):
p.setPen(text_color)
p.setOpacity(text_opacity)
font = p.font()
font.setPixelSize(1.5 * self._thumb_radius)
font.setPixelSize(int(1.5 * self._thumb_radius))
p.setFont(font)
p.drawText(
QRectF(
Expand Down Expand Up @@ -760,7 +760,7 @@ def paint(self, painter, rect, index, hover=False):
painter.save()

# Indicator ellipse rectangle
y = r.top() + (r.height() - self.indicator_side) / 2
y = int(r.top() + (r.height() - self.indicator_side) / 2)
x = r.left() + self.indicator_border
w = self.indicator_side
h = self.indicator_side
Expand Down
4 changes: 2 additions & 2 deletions src/tribler-gui/tribler_gui/widgets/tagslineedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_cursor_visible(self, visible: bool) -> None:
if visible:
flashTime = QGuiApplication.styleHints().cursorFlashTime()
if flashTime >= 2:
self.blink_timer = self.startTimer(flashTime / 2)
self.blink_timer = self.startTimer(int(flashTime / 2))
else:
self.blink_status = False

Expand Down Expand Up @@ -246,7 +246,7 @@ def compute_tag_rects_with_range(self, lt: QPoint, height: int, tags_range: Tupl
i_r.setRect(input_rect.x(), i_r.y() + TAG_HEIGHT + TAG_VERTICAL_MARGIN, i_r.width(), i_r.height())
lt.setY(lt.y() + TAG_HEIGHT + TAG_VERTICAL_MARGIN)

lt.setX(i_r.right() + TAG_HORIZONTAL_MARGIN)
lt.setX(int(i_r.right() + TAG_HORIZONTAL_MARGIN))
self.tags[tag_index].rect = i_r

def has_selection_active(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler-gui/tribler_gui/widgets/togglebutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def paintEvent(self, event): # pylint: disable=invalid-name, unused-argument
p.setPen(text_color)
p.setOpacity(text_opacity)
font = p.font()
font.setPixelSize(1.5 * self._thumb_radius)
font.setPixelSize(int(1.5 * self._thumb_radius))
p.setFont(font)
p.drawText(
QRectF(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def fill_entries(self, files):
self.blockSignals(True)
self.clear()

self.header().setResizeMode(QHeaderView.ResizeToContents)
self.header().setSectionResizeMode(QHeaderView.ResizeToContents)
single_item_torrent = len(files) == 1

# !!! ACHTUNG !!!
Expand Down

0 comments on commit d49c83a

Please sign in to comment.