Skip to content
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

The tear down function is not executed if a munit assertion fails in the test function #49

Open
freeekanayaka opened this issue Jan 12, 2019 · 2 comments

Comments

@freeekanayaka
Copy link

If a tear down function is provided, and the associated test function executes a munit assertion like munit_assert_init(1, ==, 2), then the tear down function is not executed.

This might be a problem if some resources were allocated (e.g. temporary directories) which always need to be released.

Also, in case the test program is compiled with MUNIT_NO_FORK, then even non-persistent resources (like memory allocated by a setup function) could be leaked.

@mdorier
Copy link

mdorier commented Aug 25, 2022

I've been fighting with my unit tests for a week before I realized this. This is really problematic in some cases. In my case, the code tested needs to fork a process and open pipes or sockets to it. The tear down function is taking care of cleaning up that process, closing connections, etc. so any failure in a test creates an orphan process with connections left open and makes the subsequent test hang.

It would be really good to ensure that the tear down function is called no matter the result.

@jimkimball
Copy link

jimkimball commented Apr 6, 2023

+1 on this. I didn't lose a week but I did lose a couple hours because of this.
I merged this PR with my local copy and it looks like it fixed the problem for me: #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants