Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest: If a crash/segfault/etc. occurs during testing, is there a way to make pytest log the crash as a test failure and continue testing?

I have a few unit tests written using pytest that have successfully caused segfaults to occur. However if a segfault occurs (on my Mac) during these execution, pytest seems to quit altogether and provide no information on what caused the python interpreter to crash.

Now I could infer from the logs the specific test that was crashing and determine the values used within, but I was wondering if there was any way to be able to somehow log the crash as a regular test failure and keep iterating through my tests without stopping?

If helpful, I can try to conceive an example but I think the question should be pretty self-explanatory.

like image 475
nonbot Avatar asked Oct 18 '25 16:10

nonbot


1 Answers

Using the pytest-xdist plugin it will restart the nodes automatically when they crash, so installing the plugin and running the tests with -n1 should make py.test survive the crashing tests.

like image 69
flub Avatar answered Oct 21 '25 04:10

flub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!