14
14
15
15
# pylint: disable=protected-access
16
16
17
+ import pkg_resources
17
18
import pytest
18
19
19
20
from opentelemetry .instrumentation .dependencies import (
20
21
DependencyConflict ,
21
22
get_dependency_conflicts ,
23
+ get_dist_dependency_conflicts ,
22
24
)
23
25
from opentelemetry .test .test_base import TestBase
24
26
@@ -37,7 +39,6 @@ def test_get_dependency_conflicts_not_installed(self):
37
39
conflict = get_dependency_conflicts (["this-package-does-not-exist" ])
38
40
self .assertTrue (conflict is not None )
39
41
self .assertTrue (isinstance (conflict , DependencyConflict ))
40
- print (conflict )
41
42
self .assertEqual (
42
43
str (conflict ),
43
44
'DependencyConflict: requested: "this-package-does-not-exist" but found: "None"' ,
@@ -47,10 +48,32 @@ def test_get_dependency_conflicts_mismatched_version(self):
47
48
conflict = get_dependency_conflicts (["pytest == 5000" ])
48
49
self .assertTrue (conflict is not None )
49
50
self .assertTrue (isinstance (conflict , DependencyConflict ))
50
- print (conflict )
51
51
self .assertEqual (
52
52
str (conflict ),
53
53
'DependencyConflict: requested: "pytest == 5000" but found: "pytest {0}"' .format (
54
54
pytest .__version__
55
55
),
56
56
)
57
+
58
+ def test_get_dist_dependency_conflicts (self ):
59
+ def mock_requires (extras = ()):
60
+ if "instruments" in extras :
61
+ return [
62
+ pkg_resources .Requirement (
63
+ 'test-pkg ~= 1.0; extra == "instruments"'
64
+ )
65
+ ]
66
+ return []
67
+
68
+ dist = pkg_resources .Distribution (
69
+ project_name = "test-instrumentation" , version = "1.0"
70
+ )
71
+ dist .requires = mock_requires
72
+
73
+ conflict = get_dist_dependency_conflicts (dist )
74
+ self .assertTrue (conflict is not None )
75
+ self .assertTrue (isinstance (conflict , DependencyConflict ))
76
+ self .assertEqual (
77
+ str (conflict ),
78
+ 'DependencyConflict: requested: "test-pkg~=1.0" but found: "None"' ,
79
+ )
0 commit comments