Skip to content

Live Logs don't print stdout or stderr to file #13432

Closed as not planned
Closed as not planned
@illeatmyhat

Description

@illeatmyhat

I want to print the captured stdout, stderr and other loggers to different files for each individual test.
So I wrote a hook which changes log_file for every test.

@pytest.hookimpl
def pytest_runtest_setup(item):
    logging_plugin = item.config.pluginmanager.get_plugin("logging-plugin")
    timestamp = datetime.strftime(datetime.now(), '%Y-%m-%d_%H-%M-%S')
    logging_plugin.set_log_path(f'logs'/{item.name}_{timestamp}.log')

with a test that only raises an exception

def test_foobar():
    raise Exception("foobar")

In pyproject.toml I played around with various options for --capture=... but it didn't matter

[tool.pytest.ini_options]
log_cli = true

all I get is an empty file.

I expected to see the exception and the full stack trace.

pytest==8.3.4
macOS Sonoma 14.5 (23F79)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions