ApprovalTests.Python icon indicating copy to clipboard operation
ApprovalTests.Python copied to clipboard

Can't verify logs and function output at the same time

Open tmylk opened this issue 1 year ago • 3 comments

I tried verify_logging and it doesn't quite work as expected in this scenario. i want a separate output file for logging, and another one for function return

def fizzbuzz(n):
    out_str = "\n".join(map(lambda n: fizzbuzz_single(n), range(1, n)))
    logging.info(f"Fizzbuss log says {out_str}")
    return out_str

def test_fizzbuzz_ten():
    with verify_logging():
        verify(fizzbuzz(10)    )

suggested solution is to have two separate output files - one for logs, one for output. Some kind of NamerFactory

tmylk avatar Aug 20 '23 18:08 tmylk

Would expect test_fizzbuzz_ten.logging.approved.txt in addition test_fizzbuzz_ten.approved.txt

There are two verifies happening and if one fails the test should fail and we would need to indicate why

isidore avatar Sep 10 '23 16:09 isidore

here are three solutions: https://github.com/approvals/ApprovalTests.Python/blob/main/docs/how_to/verify_both_logs_and_results.md

isidore avatar Sep 10 '23 20:09 isidore

We want this to not be confusing and we know people get confused by when and how to use multiple verifies in a single test. A warning might be helpful, especially if you are attempting to compare against the same file multiple times in one test

isidore avatar Sep 10 '23 20:09 isidore