21
21
import datetime
22
22
import functools
23
23
import os
24
+ import re
24
25
import sys
25
- import traceback
26
26
import types
27
27
28
28
from bson import json_util , Code , Decimal128 , DBRef , SON , Int64 , MaxKey , MinKey
@@ -930,8 +930,10 @@ def test_case(self):
930
930
test_method = create_test (copy .deepcopy (test_spec ))
931
931
test_method .__name__ = test_name
932
932
933
- if description in cls .EXPECTED_FAILURES :
934
- test_method = unittest .expectedFailure (test_method )
933
+ for fail_pattern in cls .EXPECTED_FAILURES :
934
+ if re .search (fail_pattern , description ):
935
+ test_method = unittest .expectedFailure (test_method )
936
+ break
935
937
936
938
setattr (cls , test_name , test_method )
937
939
@@ -947,7 +949,8 @@ def test_case(self):
947
949
948
950
949
951
def generate_test_classes (test_path , module = __name__ , class_name_prefix = '' ,
950
- expected_failures = []):
952
+ expected_failures = [],
953
+ bypass_test_generation_errors = False ):
951
954
"""Method for generating test classes. Returns a dictionary where keys are
952
955
the names of test classes and values are the test class objects."""
953
956
test_klasses = {}
@@ -979,17 +982,22 @@ class SpecTestBase(with_metaclass(UnifiedSpecTestMeta)):
979
982
test_type .replace ('-' , '_' ).replace ('.' , '_' ))
980
983
class_name = snake_to_camel (snake_class_name )
981
984
982
- schema_version = Version .from_string (
983
- scenario_def ['schemaVersion' ])
984
- mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS .get (
985
- schema_version [0 ])
986
- if mixin_class is None :
987
- raise ValueError (
988
- "test file '%s' has unsupported schemaVersion '%s'" % (
989
- fpath , schema_version ))
990
- test_klasses [class_name ] = type (
991
- class_name ,
992
- (mixin_class , test_base_class_factory (scenario_def ),),
993
- {'__module__' : module })
985
+ try :
986
+ schema_version = Version .from_string (
987
+ scenario_def ['schemaVersion' ])
988
+ mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS .get (
989
+ schema_version [0 ])
990
+ if mixin_class is None :
991
+ raise ValueError (
992
+ "test file '%s' has unsupported schemaVersion '%s'" % (
993
+ fpath , schema_version ))
994
+ test_klasses [class_name ] = type (
995
+ class_name ,
996
+ (mixin_class , test_base_class_factory (scenario_def ),),
997
+ {'__module__' : module })
998
+ except Exception :
999
+ if bypass_test_generation_errors :
1000
+ continue
1001
+ raise
994
1002
995
1003
return test_klasses
0 commit comments