Skip to content

Commit cd9dacf

Browse files
bigbZikYury Krasouski
authored andcommitted
Fix for logging (#77)
- adding check for logging class patching to avoid double patching. Fix #70 - changes in readme file example: fixture scope was changed to "session" and adding handler to logger was removed wq# Please enter the commit message for your changes. Lines starting
1 parent 5009e92 commit cd9dacf

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ in conftest.py:
7373

7474
.. code-block:: python
7575
76-
@pytest.fixture(scope="function")
76+
@pytest.fixture(scope="session")
7777
def rp_logger(request):
7878
import logging
7979
# Import Report Portal logger and handler to the test module.
@@ -86,8 +86,6 @@ in conftest.py:
8686
rp_handler = RPLogHandler(request.node.config.py_test_service)
8787
# Set INFO level for Report Portal handler.
8888
rp_handler.setLevel(logging.INFO)
89-
# Add handler to the logger.
90-
logger.addHandler(rp_handler)
9189
return logger
9290
9391
in tests:

pytest_reportportal/rp_logging.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
141141
return record
142142
return makeRecord
143143

144-
logger_class._log = wrap_log(logger_class._log)
145-
logger_class.makeRecord = wrap_makeRecord(logger_class.makeRecord)
144+
if not hasattr(logger_class, "_patched"):
145+
logger_class._log = wrap_log(logger_class._log)
146+
logger_class.makeRecord = wrap_makeRecord(logger_class.makeRecord)
147+
logger_class._patched = True
146148

147149
yield
148150

0 commit comments

Comments
 (0)