MCPcopy Create free account
hub / github.com/ycm-core/YouCompleteMe / ExpectedFailure

Function ExpectedFailure

python/ycm/tests/test_utils.py:742–782  ·  view source on GitHub ↗

Defines a decorator to be attached to tests. This decorator marks the test as being known to fail, e.g. where documenting or exercising known incorrect behaviour. The parameters are: - |reason| a textual description of the reason for the known issue. This is used for the sk

( reason, *exception_matchers )

Source from the content-addressed store, hash-verified

740
741
742def ExpectedFailure( reason, *exception_matchers ):
743 """Defines a decorator to be attached to tests. This decorator
744 marks the test as being known to fail, e.g. where documenting or exercising
745 known incorrect behaviour.
746
747 The parameters are:
748 - |reason| a textual description of the reason for the known issue. This
749 is used for the skip reason
750 - |exception_matchers| additional arguments are hamcrest matchers to apply
751 to the exception thrown. If the matchers don't match, then the
752 test is marked as error, with the original exception.
753
754 If the test fails (for the correct reason), then it is marked as skipped.
755 If it fails for any other reason, it is marked as failed.
756 If the test passes, then it is also marked as failed."""
757 def decorator( test ):
758 @functools.wraps( test )
759 def Wrapper( *args, **kwargs ):
760 try:
761 test( *args, **kwargs )
762 except Exception as test_exception:
763 # Ensure that we failed for the right reason
764 test_exception_message = ToUnicode( test_exception )
765 try:
766 for matcher in exception_matchers:
767 assert_that( test_exception_message, matcher )
768 except AssertionError:
769 # Failed for the wrong reason!
770 import traceback
771 print( 'Test failed for the wrong reason: ' + traceback.format_exc() )
772 # Real failure reason is the *original* exception, we're only trapping
773 # and ignoring the exception that is expected.
774 raise test_exception
775
776 # Failed for the right reason
777 skip( reason )
778 else:
779 raise AssertionError( f'Test was expected to fail: { reason }' )
780 return Wrapper
781
782 return decorator

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected