Skip to content

Commit 26bf400

Browse files
committed
wait launch in agent
1 parent 8b2385e commit 26bf400

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

README.rst

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,39 @@ Examples
6969

7070
For logging of the test item flow to Report Portal, please, use the python
7171
logging handler provided by plugin like bellow:
72-
72+
in conftest.py:
7373
.. code-block:: python
7474
75-
import logging
76-
# Import Report Portal logger and handler to the test module.
77-
from pytest_reportportal import RPLogger, RPLogHandler
78-
# Setting up a logging.
79-
logging.setLoggerClass(RPLogger)
80-
logger = logging.getLogger(__name__)
81-
logger.setLevel(logging.DEBUG)
82-
# Create handler for Report Portal.
83-
rp_handler = RPLogHandler()
84-
# Set INFO level for Report Portal handler.
85-
rp_handler.setLevel(logging.INFO)
86-
# Add handler to the logger.
87-
logger.addHandler(rp_handler)
88-
75+
@pytest.fixture(scope="function")
76+
def rp_logger(request):
77+
import logging
78+
# Import Report Portal logger and handler to the test module.
79+
from pytest_reportportal import RPLogger, RPLogHandler
80+
# Setting up a logging.
81+
logging.setLoggerClass(RPLogger)
82+
logger = logging.getLogger(__name__)
83+
logger.setLevel(logging.DEBUG)
84+
# Create handler for Report Portal.
85+
rp_handler = RPLogHandler(request.node.config.py_test_service)
86+
# Set INFO level for Report Portal handler.
87+
rp_handler.setLevel(logging.INFO)
88+
# Add handler to the logger.
89+
logger.addHandler(rp_handler)
90+
return logger
91+
in tests:
92+
.. code-block:: python
8993
9094
# In this case only INFO messages will be sent to the Report Portal.
91-
def test_one():
92-
logger.info("Case1. Step1")
95+
def test_one(rp_logger):
96+
rp_logger.info("Case1. Step1")
9397
x = "this"
94-
logger.info("x is: %s", x)
98+
rp_logger.info("x is: %s", x)
9599
assert 'h' in x
96100
97101
# Message with an attachment.
98102
import subprocess
99103
free_memory = subprocess.check_output("free -h".split())
100-
logger.info(
104+
rp_logger.info(
101105
"Case1. Memory consumption",
102106
attachment={
103107
"name": "free_memory.txt",
@@ -107,7 +111,7 @@ logging handler provided by plugin like bellow:
107111
)
108112
109113
# This debug message will not be sent to the Report Portal.
110-
logger.debug("Case1. Debug message")
114+
rp_logger.debug("Case1. Debug message")
111115
112116
Plugin can report doc-strings of tests as :code:`descriptions`:
113117

pytest_reportportal/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from .rp_logging import RPLogger, RPLogHandler
22

33
__all__ = ['RPLogger', 'RPLogHandler']
4+
5+
LAUNCH_WAIT_TIMEOUT = 10

pytest_reportportal/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dill as pickle
66
import pytest
77
import time
8+
from pytest_reportportal import LAUNCH_WAIT_TIMEOUT
89
from .service import PyTestServiceClass
910
from .listener import RPReportListener
1011

@@ -53,7 +54,7 @@ def pytest_sessionstart(session):
5354

5455

5556
def wait_launch(rp_client):
56-
timeout = time.time() + 10
57+
timeout = time.time() + LAUNCH_WAIT_TIMEOUT
5758
while not rp_client.launch_id:
5859
if time.time() > timeout:
5960
raise Exception("Launch not found")

0 commit comments

Comments
 (0)