def test_reordering_context(): ctx = Dummy() # top context ctx.assert_(False) with _bdd._ReorderingContext(ctx): ctx.assert_(True) raise _bdd._NeedsReordering() ctx.assert_(False) # nested context ctx._reordering_context = True with nt.assert_raises(_bdd._NeedsReordering): with _bdd._ReorderingContext(ctx): ctx.assert_(True) raise _bdd._NeedsReordering() ctx.assert_(True) # other exception ctx._reordering_context = False with nt.assert_raises(AssertionError): with _bdd._ReorderingContext(ctx): ctx.assert_(True) raise AssertionError() ctx.assert_(False) ctx._reordering_context = True with nt.assert_raises(Exception): with _bdd._ReorderingContext(ctx): raise Exception() ctx.assert_(True)