reportportal / agent-python-pytest

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

Log batches are not flushed when the test is not run in the main process #272

Closed lukaspj closed 2 years ago

lukaspj commented 3 years ago

Describe the bug This agent batches logs, these batches are not always flushed. We believe this happens when the test is not run in the main thread.

Steps to Reproduce Steps to reproduce the behavior:

  1. Run tests in multiple threads using xdist

Expected behavior Batches should flush, perhaps after every test?

Actual behavior Batches would not flush, resulting in no output showing in Report Portal

Package versions Include version info of the following packages: reportportal-client, pytest-reportportal

Additional context We have found two possible work-arounds for this issue:

Either set rp_log_batch_size = 0 in pytest.ini

Or add this hook in conftest.py:

def pytest_runtest_teardown(item):
    """Workaround for an issue in Report Portal
    The Report Portal agent gets confused when the test runs in parallel,
    This can cause log-statements to not be successfully sent to Report Portal.

    This hook ensures that the batches of logs are properly flushed for all
    threads at the end of the test.
    """
    # Flushes the log batch at the end of each test
    if hasattr(item.config, 'py_test_service'):
        item.config.py_test_service.rp.terminate()
iivanou commented 3 years ago

Looks like an issue. Terminate service at the end of the test is not a good idea...