Repository navigation
Replies: 1 comment
|
You can collect this through pytest's setup and teardown reports, without changing the test classes. Put this in from pathlib import Path
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
for heading, content in report.sections:
if heading == f"Captured stdout {report.when}":
with Path("class-output.log").open("a", encoding="utf-8") as file:
file.write(f"{item.nodeid} {report.when}:\n{content}")I tested this with a class containing two tests on pytest 9.1.1. The |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi,
The company I work for have implemented the tests in such a way that all the tests aren't using fixtures but setup_class and teardown_class
How can I hook to this object to print it's output to a file? (I'm doing it for tests just not for setup_class and teardown_class)
All reactions