reportportal / agent-python-pytest

Framework integration with PyTest
Apache License 2.0
94 stars 102 forks source link

reportportal plugin fails to send logs from threads #310

Closed borislitvinov closed 2 years ago

borislitvinov commented 2 years ago

Describe the bug It seems like all log messages sent from function wrapped by threading.Thread fails to reach the RP

Steps to Reproduce

import threading

def worker():
   # both INFO and DEBUG 
    log.info("TEST_INFO") 
    log.debug("TEST_DEBUG")

def test_log():
    t = threading.Thread(target=worker)
    log.info("TEST_BEFORE_THREADING") # this message can be seen in RP
    t.start()
    t.join()

Expected behavior all the messages should exist in RP

Actual behavior The message from "worker" can be seen in pytest's cli log , but not in RP

Package versions pytest-reportportal 5.1.1 reportportal-client 5.2.2

Additional context Add any other context about the problem here.

HardNorth commented 2 years ago

@borislitvinov Yes, this is a known limitation of Python at all. There is no way to track parent / child thread. Actually, the whole threading model is neglected in the language. So just don't use threads, use processes if you need multi-threading in Python, this is Python's official answer: https://docs.python.org/3.7/glossary.html#term-global-interpreter-lock

HardNorth commented 2 years ago

@borislitvinov Implemented a possible workaround in our examples: https://github.com/reportportal/examples-python/blob/master/pytest/tests/test_thread_logging.py

Sorry, I couldn't invent anything but passing the logger explicitly in function parameters.

borislitvinov commented 2 years ago

@HardNorth Thanks for the WA you have provided .

dagansandler commented 1 year ago

@HardNorth I have been working on a PR to add support for this use case. It's disabled by default and only enabled by usage of a dedicated flag. Please take a look at the PR: https://github.com/reportportal/agent-python-pytest/pull/320