Skip to content

Commit 15a9588

Browse files
committed
adding a test to validate new flag
1 parent 6820401 commit 15a9588

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

examples/threads/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
import threading
3+
4+
from reportportal_client.steps import step
5+
6+
log = logging.getLogger(__name__)
7+
8+
9+
def worker():
10+
log.info("TEST_INFO")
11+
log.debug("TEST_DEBUG")
12+
13+
14+
def test_log():
15+
t = threading.Thread(target=worker)
16+
log.info("TEST_BEFORE_THREADING")
17+
with step("Some nesting where the thread logs should go"):
18+
t.start()
19+
t.join()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from six.moves import mock
2+
3+
from tests import REPORT_PORTAL_SERVICE
4+
from tests.helpers import utils
5+
6+
7+
@mock.patch('pytest_reportportal.rp_logging.RPClient')
8+
@mock.patch(REPORT_PORTAL_SERVICE)
9+
def test_rp_thread_logs_reporting(mock_client_init, mock_thread_client_init):
10+
"""Verify logs from threads are sent to correct items`.
11+
12+
:param mock_client_init: Pytest fixture
13+
"""
14+
mock_client = mock_client_init.return_value
15+
mock_thread_client = mock_thread_client_init.return_value
16+
17+
def init_thread_client(*_, **__):
18+
from reportportal_client._local import set_current
19+
set_current(mock_thread_client)
20+
return mock_thread_client
21+
mock_thread_client_init.side_effect = init_thread_client
22+
result = utils.run_tests_with_client(
23+
mock_client,
24+
['examples/threads/'],
25+
args=["--rp-thread-logging"]
26+
)
27+
28+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
29+
assert mock_client.start_launch.call_count == 1, \
30+
'"start_launch" method was not called'
31+
assert mock_client.log.call_count == 1
32+
assert mock_thread_client.log.call_count == 2

0 commit comments

Comments
 (0)