I want to save the log files from pytest test runs only when the tests are unsuccessful, this could be from an error in the test fixtures setup or a failure in the tests themselves.
My approach for this is to create a test fixture that copies the logs following a yield, but I can't figure out how to make it conditional on the test outcome.
@pytest.fixture
def setup():
do_setup()
yield
do_teardown()
@pytest.fixture
def get_logs():
yield
if not test_success: # how to know this condition?
copy_log_files()
def test_run(get_logs, setup):
do_test_stuff()