-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Live Logs don't print stdout or stderr to file #13432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For anyone who really only cares about the final exception trace, and not any stray test_start = pytest.StashKey[datetime]()
@pytest.hookimpl
def pytest_collection_modifyitems(config, items):
for item in items:
item.stash[test_start] = datetime.strftime(datetime.now(), '%Y-%m-%d_%H-%M-%S')
@pytest.hookimpl
def pytest_runtest_setup(item):
logging_plugin = item.config.pluginmanager.get_plugin("logging-plugin")
log_file = Path('logs') / item.stash[test_start] / f'{item.name}.log'
logging_plugin.set_log_path(log_file)
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
result: TestReport = outcome.get_result()
log_file = Path('logs') / item.stash[test_start] / f'{item.name}.log'
if result.when == 'call' and result.failed:
filepath, lineno, testname = result.location
with log_file.open('a') as f:
f.write(f'{filepath}:{lineno} ({testname})\n{result.longreprtext}') |
I don't understand how this would be a bug. The logging plugin handles Python logging. Exceptions are a different Python feature and don't magically end up as a logging record. |
Is that not besides the point? I thought this feature was supposed to be better than |
The point of the feature is seeing logging output from Python (usually generated by your application) as that's happening. It's not intended to give you a log of the test run. |
Uh oh!
There was an error while loading. Please reload this page.
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.with a test that only raises an exception
In
pyproject.toml
I played around with various options for--capture=...
but it didn't matterall 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)
The text was updated successfully, but these errors were encountered: