@@ -1038,32 +1038,13 @@ def client_response_hook(send_span, scope, message):
1038
1038
1039
1039
1040
1040
def get_distribution_with_fastapi (* args , ** kwargs ):
1041
- print ("JEREVOSS get_distribution_with_fastapi" )
1042
- print ("args: %s" % args )
1043
- print ("kwargs: %s" % kwargs )
1044
1041
dist = args [0 ]
1045
- print ("JEREVOSS get_distribution_with_fastapi: dist: %s" % dist )
1046
1042
if dist == "fastapi~=0.58" :
1047
1043
return None #Value does not matter. Only whether an exception is thrown
1048
- elif "fastapi-slim" in dist :
1049
- raise DistributionNotFound ()
1050
- else :
1051
- return None #TODO: may want to change to not found
1044
+ raise DistributionNotFound ()
1052
1045
1053
1046
def get_distribution_without_fastapi (* args , ** kwargs ):
1054
- print ("JEREVOSS get_distribution_without_fastapi" )
1055
- print ("args: %s" % args )
1056
- print ("kwargs: %s" % kwargs )
1057
- dist = args [0 ]
1058
- print ("JEREVOSS get_distribution_without_fastapi: dist: %s" % dist )
1059
- if dist == "fastapi~=0.58" :
1060
- print ("JEREVOSS get_distribution_without_fastapi IF: dist: %s" % dist )
1061
- raise DistributionNotFound ()
1062
- elif "fastapi-slim" in dist :
1063
- raise DistributionNotFound ()
1064
- else :
1065
- print ("JEREVOSS get_distribution_without_fastapi ELSE: dist: %s" % dist )
1066
- return None #TODO: may want to change to not found
1047
+ raise DistributionNotFound ()
1067
1048
1068
1049
1069
1050
class TestAutoInstrumentation (TestBaseAutoFastAPI ):
@@ -1084,64 +1065,37 @@ def test_entry_point_exists(self):
1084
1065
self .assertEqual (ep .name , 'fastapi' )
1085
1066
self .assertIsNone (next (eps , None ))
1086
1067
1087
- # @patch("pkg_resources.get_distribution", side_effect=get_distribution_with_fastapi)
1088
1068
@patch ("opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts" )
1089
1069
@patch ("opentelemetry.instrumentation.dependencies.get_dependency_conflicts" )
1090
1070
@patch ("opentelemetry.instrumentation.dependencies.get_distribution" )
1091
1071
def test_instruments_with_fastapi_installed (self , mock_get_distribution , mock_get_dependency_conflicts , mock_get_dist_dependency_conflicts ):
1092
- # Need to use matchers
1093
- # mock_get_distribution.side_effect = TestAutoInstrumentationget_distribution_with_fastapi
1094
- # mock_get_distribution("foobar").side_effect = DistributionNotFound()
1095
- # mock_get_distribution("fastapi-slim ~= 0.111").side_effect = DistributionNotFound()
1096
- # mock_get_distribution("fastapi ~= 0.58").return_value = None #Value does not matter. Only whether an exception is thrown
1097
1072
mock_get_dist_dependency_conflicts .side_effect = get_dist_dependency_conflicts
1098
1073
mock_get_dependency_conflicts .side_effect = get_dependency_conflicts
1099
1074
mock_get_distribution .side_effect = get_distribution_with_fastapi
1100
1075
mock_distro = Mock ()
1101
1076
_load_instrumentors (mock_distro )
1102
- print ("JEREVOSS mock_get_dist_dependency_conflicts.call_args_list: %s" % mock_get_dist_dependency_conflicts .call_args_list )
1103
- print ("JEREVOSS mock_get_dependency_conflicts.call_args_list: %s" % mock_get_dependency_conflicts .call_args_list )
1104
- print ("JEREVOSS mock_get_distribution.call_args_list: %s" % mock_get_distribution .call_args_list )
1105
1077
mock_get_distribution .assert_called_once_with ("fastapi~=0.58" )
1106
- # print("JEREVOSS mock_get_distribution().call_args_list: %s" % mock_get_distribution().call_args_list)
1107
1078
self .assertEqual (len (mock_distro .load_instrumentor .call_args_list ), 1 )
1108
- call_args = mock_distro .load_instrumentor .call_args
1109
- call_args_args = call_args .args
1110
- print ("JEREVOSS call_args: %s" % str (call_args ))
1111
- print (call_args )
1112
- print ("JEREVOSS call_args_args: %s" % call_args_args )
1113
- ep = call_args_args [0 ]
1079
+ args = mock_distro .load_instrumentor .call_args .args
1080
+ ep = args [0 ]
1114
1081
self .assertEqual (ep .dist .key , 'opentelemetry-instrumentation-fastapi' )
1115
1082
self .assertEqual (ep .module_name , 'opentelemetry.instrumentation.fastapi' )
1116
1083
self .assertEqual (ep .attrs , ('FastAPIInstrumentor' ,))
1117
1084
self .assertEqual (ep .name , 'fastapi' )
1118
- # mock_distro.load_instrumentor.assert_called_once_with(self.entry_point, skip_dep_check=True) Doesn't work
1119
1085
1120
- # @patch("pkg_resources.get_distribution", side_effect=get_distribution_without_fastapi)
1121
1086
@patch ("opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts" )
1122
1087
@patch ("opentelemetry.instrumentation.dependencies.get_dependency_conflicts" )
1123
1088
@patch ("opentelemetry.instrumentation.dependencies.get_distribution" )
1124
1089
def test_instruments_without_fastapi_installed (self , mock_get_distribution , mock_get_dependency_conflicts , mock_get_dist_dependency_conflicts ):
1125
- # mock_get_distribution.side_effect = get_distribution_without_fastapi
1126
- # mock_get_distribution("foobar").side_effect = DistributionNotFound()
1127
- # mock_get_distribution("fastapi-slim ~= 0.111").side_effect = DistributionNotFound()
1128
- # mock_get_distribution("fastapi ~= 0.58").side_effect = DistributionNotFound()
1129
1090
mock_get_dist_dependency_conflicts .side_effect = get_dist_dependency_conflicts
1130
1091
mock_get_dependency_conflicts .side_effect = get_dependency_conflicts
1131
1092
mock_get_distribution .side_effect = get_distribution_without_fastapi
1132
1093
mock_distro = Mock ()
1133
1094
_load_instrumentors (mock_distro )
1134
- print ("JEREVOSS mock_get_dist_dependency_conflicts.call_args_list: %s" % mock_get_dist_dependency_conflicts .call_args_list )
1135
- print ("JEREVOSS mock_get_dependency_conflicts.call_args_list: %s" % mock_get_dependency_conflicts .call_args_list )
1136
- print ("JEREVOSS mock_get_distribution.call_args_list: %s" % mock_get_distribution .call_args_list )
1137
- print ("JEREVOSS mock_get_distribution.side_effect: %s" % mock_get_distribution .side_effect )
1138
1095
mock_get_distribution .assert_called_once_with ("fastapi~=0.58" )
1139
- print ("-----\n JEREVOSS about to test error" )
1140
1096
with self .assertRaises (DistributionNotFound ):
1141
1097
mock_get_distribution ("fastapi~=0.58" )
1142
1098
self .assertEqual (len (mock_distro .load_instrumentor .call_args_list ), 0 )
1143
- # print("JEREVOSS mock_get_distribution().call_args_list: %s" % mock_get_distribution().call_args_list)
1144
- # mock_get_distribution.assert_called_once_with("fastapi ~= 0.58")
1145
1099
mock_distro .load_instrumentor .assert_not_called ()
1146
1100
1147
1101
def _create_app (self ):
0 commit comments