|
14 | 14 |
|
15 | 15 | # pylint: disable=protected-access
|
16 | 16 |
|
17 |
| -from opentelemetry.util._importlib_metadata import Distribution, requires |
18 |
| -from packaging.requirements import Requirement |
19 | 17 | import pytest
|
| 18 | +from packaging.requirements import Requirement |
20 | 19 |
|
21 | 20 | from opentelemetry.instrumentation.dependencies import (
|
22 | 21 | DependencyConflict,
|
23 | 22 | get_dependency_conflicts,
|
24 | 23 | get_dist_dependency_conflicts,
|
25 | 24 | )
|
26 | 25 | from opentelemetry.test.test_base import TestBase
|
| 26 | +from opentelemetry.util._importlib_metadata import Distribution |
27 | 27 |
|
28 | 28 |
|
29 | 29 | class TestDependencyConflicts(TestBase):
|
@@ -66,20 +66,23 @@ def test_get_dependency_conflicts_mismatched_version(self):
|
66 | 66 | )
|
67 | 67 |
|
68 | 68 | def test_get_dist_dependency_conflicts(self):
|
69 |
| - def mock_requires(extras=()): |
70 |
| - if "instruments" in extras: |
71 |
| - return requires( |
72 |
| - 'test-pkg ~= 1.0; extra == "instruments"' |
73 |
| - ) |
74 |
| - return [] |
| 69 | + class MockDistribution(Distribution): |
| 70 | + def locate_file(self, path): |
| 71 | + pass |
| 72 | + |
| 73 | + def read_text(self, filename): |
| 74 | + pass |
| 75 | + |
| 76 | + @property |
| 77 | + def requires(self): |
| 78 | + return ['test-pkg ~= 1.0; extra == "instruments"'] |
75 | 79 |
|
76 |
| - dist = Distribution() |
77 |
| - dist.requires = mock_requires |
| 80 | + dist = MockDistribution() |
78 | 81 |
|
79 | 82 | conflict = get_dist_dependency_conflicts(dist)
|
80 | 83 | self.assertTrue(conflict is not None)
|
81 | 84 | self.assertTrue(isinstance(conflict, DependencyConflict))
|
82 | 85 | self.assertEqual(
|
83 | 86 | str(conflict),
|
84 |
| - 'DependencyConflict: requested: "test-pkg~=1.0" but found: "None"', |
| 87 | + 'DependencyConflict: requested: "test-pkg~=1.0; extra == "instruments"" but found: "None"', |
85 | 88 | )
|
0 commit comments