Handle expected AssertionError and AssumptionViolatedException.

Fixes #687.