Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.
This repository was archived by the owner on May 27, 2024. It is now read-only.

Propagate log records to main process #5

Description

@uSpike

Hi thanks for publishing this project. We're doing something similar and I'd love to share some things that we've done.

pytest has better built-in support for logging, both capturing, live-logging, and writing to the junit-xml file (pytest-dev/pytest#3156). Log files are usually written in pytest_sessionfinish so we need them to propagate to the main process.

We solved this with the following:

## main process
class _ReEmitHandler(logging.Handler):
    def handle(self, record):
        logging.getLogger(record.name).handle(record)

log_queue = manager.Queue()
listener = logging.handlers.QueueListener(log_queue, _ReEmitHandler)
listener.start()

## subprocess
root = logging.getLogger()
root.handlers.clear()
root.addHandler(logging.handlers.QueueHandler(log_queue))
... run tests

Interested in a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions