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

Propagate log records to main process #5

Open
uSpike opened this issue Feb 8, 2018 · 1 comment
Open

Propagate log records to main process #5

uSpike opened this issue Feb 8, 2018 · 1 comment

Comments

@uSpike
Copy link
Contributor

uSpike commented Feb 8, 2018

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?

@rmfitzpatrick
Copy link
Contributor

I'm very interested in a PR, but would prefer that we not track the features branch too closely re: junit-xml logging. A clear path of working w/ core plugin changes remains to be developed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants