Replies: 1 comment 2 replies
-
Hi @choppsv1, I think you will need a custom plugin that implements # content of conftest.py
def pytest_runtest_call(item: pytest.Item) -> None:
with capture_mem_leaks() as leaks:
item.runtest()
if leaks:
pytest.fail(f"test {item.name} leaked memory: {leaks}") |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
tl;dr -- Is there a way to hook into each test run just after the test has run but in a place where I can still call pytest.fail() and have the right thing happen?
We have a testing framework built upon pytest for
FRR
. A custom option we added was--valgrind-memleaks
which causes all the FRR daemons to be run under valgrind. I've written a check that looks for new valgrind files generated from memleaks. I'd really like to fail the test when this check finds new memleaks files so that we see that this test in particular caused a memleak. Ideally I'd just use a fixture, yield to the test and then do the check after, but this will cause a pytest error instead of a test failure -- which then won't be logged/collected/noted by all the CI infrastructure etc which is looking for test failures.The code (broken) currently tries to use and catch a pytest.fail() from inside a try/except statement to try and construct a excinfo to plug into the call.excinfo in a make report hook but this doesn't seem to work right and seems hackish anyway.
Beta Was this translation helpful? Give feedback.
All reactions