Skip to content
Closed
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
48 changes: 46 additions & 2 deletions colcon_core/task/python/test/pytest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Copyright 2016-2018 Dirk Thomas
# Copyright 2016-2019 Dirk Thomas
# Licensed under the Apache License, Version 2.0

import os
from pathlib import Path
from pathlib import PurePosixPath
import sys
import traceback
import types

from colcon_core.event.output import StderrLine
from colcon_core.event.output import StdoutLine
from colcon_core.event.test import TestFailure
from colcon_core.plugin_system import satisfies_version
from colcon_core.plugin_system import SkipExtensionException
Expand Down Expand Up @@ -151,7 +155,47 @@ async def step(self, context, env, setup_py_data): # noqa: D102
</testsuite>
""".format_map(locals())) # noqa: E501

rc = await check_call(context, cmd, cwd=context.args.path, env=env)
# redirect the warnings summary to stderr to make it visible by default
def redirect_warnings_summary_to_stderr(put_event_into_queue):
within_warnings_summary = False

def put_event_into_queue_(self, event):
nonlocal put_event_into_queue
nonlocal within_warnings_summary
if isinstance(event, StdoutLine):
try:
str_line = str(event.line, errors='replace')
if '=== warnings summary ===' in str_line:
within_warnings_summary = True
if within_warnings_summary:
event = StderrLine(event.line)
if (
str_line.startswith('-- Docs: ') and
'/warnings.html' in str_line
):
within_warnings_summary = False
except Exception as e: # noqa: F841
# otherwise the actual exception is not visible and
# only 'error: [Errno 5] Input/output error' is shown
exc = traceback.format_exc()
logger.error(
'Exception within '
"'redirect_warnings_summary_to_stderr': {e}\n{exc}"
.format_map(locals()))
raise
return put_event_into_queue(event)

return put_event_into_queue_

# override 'put_event_into_queue' and restore after the call
put_event_into_queue = context.put_event_into_queue
context.put_event_into_queue = types.MethodType(
redirect_warnings_summary_to_stderr(
context.put_event_into_queue), context)
try:
rc = await check_call(context, cmd, cwd=context.args.path, env=env)
finally:
context.put_event_into_queue = put_event_into_queue

# use local import to avoid a dependency on pytest
try:
Expand Down